]> wimlib.net Git - wimlib/blobdiff - src/win32_apply.c
Win32: Use OPEN_EXISTING creation disposition on drive root
[wimlib] / src / win32_apply.c
index 7b7ff27ba29bf68504ce88a98c59031e6adee875..972224efad978188b191c217508fe734ba2fd2a8 100644 (file)
@@ -482,9 +482,12 @@ do_win32_extract_encrypted_stream(const wchar_t *path,
 static bool
 path_is_root_of_drive(const wchar_t *path)
 {
-       if (!*path)
+       if (*path == L'\0')
                return false;
 
+       if (!wcsncmp(path, L"\\\\?\\", 4))
+               path += 4;
+
        if (*path != L'/' && *path != L'\\') {
                if (*(path + 1) == L':')
                        path += 2;
@@ -598,18 +601,19 @@ win32_begin_extract_unnamed_stream(const struct wim_inode *inode,
        /* Directories must be created with CreateDirectoryW().  Then the call
         * to CreateFileW() will merely open the directory that was already
         * created rather than creating a new file. */
-       if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY &&
-           !path_is_root_of_drive(path)) {
-               if (!CreateDirectoryW(path, NULL)) {
-                       err = GetLastError();
-                       if (err != ERROR_ALREADY_EXISTS) {
-                               ERROR("Failed to create directory \"%ls\"",
-                                     path);
-                               win32_error(err);
-                               return WIMLIB_ERR_MKDIR;
+       if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) {
+               if (!path_is_root_of_drive(path)) {
+                       if (!CreateDirectoryW(path, NULL)) {
+                               err = GetLastError();
+                               if (err != ERROR_ALREADY_EXISTS) {
+                                       ERROR("Failed to create directory \"%ls\"",
+                                             path);
+                                       win32_error(err);
+                                       return WIMLIB_ERR_MKDIR;
+                               }
                        }
+                       DEBUG("Created directory \"%ls\"", path);
                }
-               DEBUG("Created directory \"%ls\"", path);
                *creationDisposition_ret = OPEN_EXISTING;
        }
        if (inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED &&