commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r789606 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Date Tue, 30 Jun 2009 08:17:23 GMT
Author: mturk
Date: Tue Jun 30 08:17:22 2009
New Revision: 789606

URL: http://svn.apache.org/viewvc?rev=789606&view=rev
Log:
Always change forward to backward slashes

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789606&r1=789605&r2=789606&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 08:17:22 2009
@@ -30,6 +30,36 @@
  *
  */
 
+/*
+ * 1. Remove  \\?\ prefix
+ * 2. Replace UNC\ with \\
+ */
+static __inline wchar_t *NO2UNC(wchar_t *fname)
+{
+    if (wcsncmp(fname, L"\\\\?\\", 4) == 0) {
+        fname += 4;
+        if (wcsncmp(fname, L"UNC\\", 4) == 0) {
+            fname += 2;
+            *fname = L'\\';
+        }
+        else if (wcsncmp(fname, L"UN\\\\", 4) == 0) {
+            /* Already modified in-place.
+             */
+            fname += 2;
+        }
+    }
+    return fname;
+}
+
+static __inline void FS2BS(wchar_t *path)
+{
+    size_t i;
+    for (i = 0; i < wcslen(path); i++) {
+        if (path[i] == L'/')
+            path[i] = L'\\';
+    }
+}
+
 ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const wchar_t *fname)
 {
     WIN32_FILE_ATTRIBUTE_DATA info;
@@ -97,6 +127,7 @@
 
     UNREFERENCED_O;
     WITH_WSTR(pathname) {
+        FS2BS(J2W(pathname));
         type = ACR_FileTypeGet(_E, J2W(pathname));
     } END_WITH_WSTR(pathname);
 
@@ -117,6 +148,7 @@
         DWORD  dwFlags = 0;
         size_t tlen = wcslen(J2W(target));
 
+        FS2BS(J2W(target));
         if (ACR_FileTypeGet(NULL, J2W(target)) == ACR_FT_DIR) {
             dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY;
         }
@@ -231,6 +263,8 @@
     UNREFERENCED_O;
     WITH_WSTR(target) {
     WITH_WSTR(lnkname) {
+        FS2BS(J2W(target));
+        FS2BS(J2W(lnkname));
         if (!CreateHardLinkW(J2W(lnkname), J2W(target), NULL)) {
             int err = ACR_GET_OS_ERROR();
             if (ACR_STATUS_IS_EACCES(err)) {
@@ -252,10 +286,12 @@
                                               jstring lnkname)
 {
     jstring rv = NULL;
+    int ex = 0;
 
     UNREFERENCED_O;
     WITH_WSTR(lnkname) {
         void *buf = ACR_Calloc(_E, THROW_FMARK, MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
+        FS2BS(J2W(lnkname));
         if (buf) {
             HANDLE sh = CreateFileW(J2W(lnkname),
                                     GENERIC_READ,
@@ -318,19 +354,21 @@
                         }
                     break;
                     default:
-                        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ACR_EBADF);
+                        ex = ACR_EBADF;
                     break;
                 }
                 CloseHandle(sh);
             }
             else {
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                                    ACR_GET_OS_ERROR());
+                ex = ACR_GET_OS_ERROR();
             }
             free(buf);
         }
 
     } END_WITH_WSTR(lnkname);
+    if (ex) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
+    }
     return rv;
 }
 
@@ -427,20 +465,6 @@
     int fix = 0;
     int rc;
 
-    if (wcsncmp(fname, L"\\\\?\\", 4) == 0) {
-        fname += 4;
-        if (wcsncmp(fname, L"UNC\\", 4) == 0) {
-            /* TODO: Do not modify in fname in-place.
-             */
-            fname += 2;
-            *fname = L'\\';
-        }
-        else if (wcsncmp(fname, L"UN\\\\", 4) == 0) {
-            /* Already modified in-place.
-             */
-            fname += 2;
-        }
-    }
     rc = GetNamedSecurityInfoW(fname,
                                SE_FILE_OBJECT,
                                OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
DACL_SECURITY_INFORMATION,
@@ -556,18 +580,6 @@
     int fix = 0;
     int rc;
 
-    if (wcsncmp(fname, L"\\\\?\\", 4) == 0) {
-        fname += 4;
-        if (wcsncmp(fname, L"UNC\\", 4) == 0) {
-            fname += 2;
-            *fname = L'\\';
-        }
-        else if (wcsncmp(fname, L"UN\\\\", 4) == 0) {
-            /* Already modified in-place.
-             */
-            fname += 2;
-        }
-    }
     rc = GetNamedSecurityInfoW(fname,
                                SE_FILE_OBJECT,
                                OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
DACL_SECURITY_INFORMATION,
@@ -621,6 +633,7 @@
 
     UNREFERENCED_O;
     WITH_WSTR(pathname) {
+        FS2BS(J2W(pathname));
         prot = ACR_FileProtectionGet(_E, J2W(pathname));
     } END_WITH_WSTR(pathname);
 
@@ -635,6 +648,7 @@
     UNREFERENCED_O;
 
     WITH_WSTR(pathname) {
+        FS2BS(J2W(pathname));
         rc = ACR_FileProtectionSet(_E, J2W(pathname), prot);
     } END_WITH_WSTR(pathname);
 
@@ -673,6 +687,7 @@
             sec |= OWNER_SECURITY_INFORMATION;
         if (sgrp)
             sec |= GROUP_SECURITY_INFORMATION;
+        FS2BS(J2W(pathname));
         rc = SetNamedSecurityInfoW(J2W(pathname),
                                    SE_FILE_OBJECT,
                                    sec,
@@ -703,6 +718,7 @@
     UNREFERENCED_O;
 
     WITH_WSTR(pathname) {
+        FS2BS(J2W(pathname));
         flags = GetFileAttributesW(J2W(pathname));
         if (flags == 0xFFFFFFFF)
             rc = GetLastError();



Mime
View raw message