From 93843920ce69aaac7414ea2eaaac54b85f6f5584 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 29 Apr 2014 17:20:58 -0500 Subject: [PATCH] Strip trailing slashes from Windows filesystem paths --- src/extract.c | 12 ++++++++++++ src/win32_capture.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/extract.c b/src/extract.c index 1b7eb6bc..b1f62b12 100644 --- a/src/extract.c +++ b/src/extract.c @@ -2529,6 +2529,18 @@ extract_trees(WIMStruct *wim, struct wim_dentry **trees, size_t num_trees, goto out_destroy_stream_list; } ctx.realtarget_nchars = tstrlen(ctx.realtarget); + #ifdef __WIN32__ + /* Strip trailing slashes. If we don't do this, we may create a + * path with multiple consecutive backslashes, which for some + * reason causes Windows to report that the file cannot be found. + */ + while (ctx.realtarget_nchars >= 2 + && ctx.realtarget[ctx.realtarget_nchars - 1] == L'\\' + && ctx.realtarget[ctx.realtarget_nchars - 2] != L':') + { + ctx.realtarget[--ctx.realtarget_nchars] = L'\0'; + } + #endif } if (progress_func) { diff --git a/src/win32_capture.c b/src/win32_capture.c index 745ee77a..c62abce7 100644 --- a/src/win32_capture.c +++ b/src/win32_capture.c @@ -1411,6 +1411,16 @@ win32_build_dentry_tree(struct wim_dentry **root_ret, wmemcpy(path, root_disk_path, path_nchars + 1); } + /* Strip trailing slashes. If we don't do this, we may create a path + * with multiple consecutive backslashes, which for some reason causes + * Windows to report that the file cannot be found. */ + while (path_nchars >= 2 && + path[path_nchars - 1] == L'\\' && + path[path_nchars - 2] != L':') + { + path[--path_nchars] = L'\0'; + } + params->capture_root_nchars = path_nchars; memset(&state, 0, sizeof(state)); -- 2.43.0