Win32: Correctly handle pattern matching with \\?\-prefixed paths
authorEric Biggers <ebiggers3@gmail.com>
Fri, 19 Jul 2013 01:59:00 +0000 (20:59 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 19 Jul 2013 02:00:24 +0000 (21:00 -0500)
The switch to using \\?\-prefixed paths made excluding files stop working
on Windows.  Fix it.

include/wimlib.h
include/wimlib/capture.h
src/win32_capture.c

index 75fde57..d80089c 100644 (file)
@@ -617,7 +617,7 @@ struct wimlib_capture_config {
        struct wimlib_pattern_list reserved2;
 
        /** Library internal use only. */
-       const wimlib_tchar *_prefix;
+       wimlib_tchar *_prefix;
 
        /** Library internal use only. */
        size_t _prefix_num_tchars;
index b60c5c8..8b67c94 100644 (file)
@@ -47,7 +47,7 @@ struct add_image_params {
 
        /* Pointer to the capture configuration, which indicates whether any
         * files should be excluded from capture or not. */
-       const struct wimlib_capture_config *config;
+       struct wimlib_capture_config *config;
 
        /* Flags that affect the capture operation (WIMLIB_ADD_FLAG_*) */
        int add_flags;
index afb38e3..2e501db 100644 (file)
@@ -1142,6 +1142,7 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
        struct win32_capture_state state;
        unsigned vol_flags;
        DWORD dret;
+       bool need_prefix_free = false;
 
        if (!win32func_FindFirstStreamW) {
                WARNING("Running on Windows XP or earlier; "
@@ -1189,6 +1190,18 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
                } else {
                        wmemcpy(path, L"\\\\?\\", 4);
                        path_nchars = 4 + dret;
+                       /* Update pattern prefix */
+                       if (params->config != NULL)
+                       {
+                               params->config->_prefix = TSTRDUP(path);
+                               params->config->_prefix_num_tchars = path_nchars;
+                               if (params->config->_prefix == NULL)
+                               {
+                                       ret = WIMLIB_ERR_NOMEM;
+                                       goto out_free_path;
+                               }
+                               need_prefix_free = true;
+                       }
                }
        } else {
                wmemcpy(path, root_disk_path, path_nchars + 1);
@@ -1198,6 +1211,9 @@ win32_build_dentry_tree(struct wim_dentry **root_ret,
        ret = win32_build_dentry_tree_recursive(root_ret, path,
                                                path_nchars, params,
                                                &state, vol_flags);
+       if (need_prefix_free)
+               FREE(params->config->_prefix);
+out_free_path:
        FREE(path);
        if (ret == 0)
                win32_do_capture_warnings(&state, params->add_flags);