]> wimlib.net Git - wimlib/blobdiff - src/win32_capture.c
win32_capture.c: Fix exclusion when capture path ends in slash
[wimlib] / src / win32_capture.c
index 6223ed26135acb26fc4da3d7d139998bc982b5f6..08a0654f812ac18573a3b22b049962998bd3c41a 100644 (file)
@@ -1110,11 +1110,19 @@ winnt_build_dentry_tree_recursive(struct wim_dentry **root_ret,
                                        SYNCHRONIZE,
                              &h);
        if (unlikely(!NT_SUCCESS(status))) {
-               set_errno_from_nt_status(status);
-               ERROR_WITH_ERRNO("\"%ls\": Can't open file "
-                                "(status=0x%08"PRIx32")",
-                                printable_path(full_path), (u32)status);
-               ret = WIMLIB_ERR_OPEN;
+               if (status == STATUS_DELETE_PENDING) {
+                       WARNING("\"%ls\": Deletion pending; skipping file",
+                               printable_path(full_path));
+                       ret = 0;
+               } else {
+                       set_errno_from_nt_status(status);
+                       ERROR_WITH_ERRNO("\"%ls\": Can't open file "
+                                        "(status=0x%08"PRIx32")",
+                                        printable_path(full_path), (u32)status);
+                       ret = WIMLIB_ERR_OPEN;
+               }
+               /* XXX: Provide option to exclude files that fail with
+                * STATUS_SHARING_VIOLATION?  */
                goto out;
        }
 
@@ -1388,6 +1396,7 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
        int ret;
        UNICODE_STRING ntpath;
        struct winnt_scan_stats stats;
+       size_t ntpath_nchars;
 
        /* WARNING: There is no check for overflow later when this buffer is
         * being used!  But it's as long as the maximum path length understood
@@ -1409,16 +1418,20 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
                goto out_free_path;
        }
 
-       params->capture_root_nchars = ntpath.Length / sizeof(wchar_t);
-       wmemcpy(path, ntpath.Buffer, params->capture_root_nchars);
-       path[params->capture_root_nchars] = L'\0';
+       ntpath_nchars = ntpath.Length / sizeof(wchar_t);
+       wmemcpy(path, ntpath.Buffer, ntpath_nchars);
+       path[ntpath_nchars] = L'\0';
+
+       params->capture_root_nchars = ntpath_nchars;
+       if (path[ntpath_nchars - 1] == L'\\')
+               params->capture_root_nchars--;
 
        HeapFree(GetProcessHeap(), 0, ntpath.Buffer);
 
        memset(&stats, 0, sizeof(stats));
 
        ret = winnt_build_dentry_tree_recursive(root_ret, NULL,
-                                               path, params->capture_root_nchars,
+                                               path, ntpath_nchars,
                                                L"", 0, params, &stats, 0);
 out_free_path:
        FREE(path);