summaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-06-03 17:48:39 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-06-07 19:44:36 -0500
commit6b0f2d978504da82070523eb6adb0b59f9812e93 (patch)
tree6f0b258519a0f51bf589e4313206b3ffeaa32a41 /src/libs/dutil/WixToolset.DUtil/dirutil.cpp
parentb652e93a460b4b822a01382e5992f96f1d805ffe (diff)
downloadwix-6b0f2d978504da82070523eb6adb0b59f9812e93.tar.gz
wix-6b0f2d978504da82070523eb6adb0b59f9812e93.tar.bz2
wix-6b0f2d978504da82070523eb6adb0b59f9812e93.zip
Add PathSkipPastRoot.
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/dirutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dirutil.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
index c106a467..94eab9e7 100644
--- a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
@@ -364,17 +364,27 @@ extern "C" DWORD DAPI DirDeleteEmptyDirectoriesToRoot(
364 __in DWORD /*dwFlags*/ 364 __in DWORD /*dwFlags*/
365 ) 365 )
366{ 366{
367 HRESULT hr = S_OK;
367 DWORD cDeletedDirs = 0; 368 DWORD cDeletedDirs = 0;
368 LPWSTR sczPath = NULL; 369 LPWSTR sczPath = NULL;
370 LPCWSTR wzPastRoot = NULL;
371 SIZE_T cchRoot = 0;
372
373 // Make sure the path is normalized and prefixed.
374 hr = PathExpand(&sczPath, wzPath, PATH_EXPAND_FULLPATH);
375 DirExitOnFailure(hr, "Failed to get full path for: %ls", wzPath);
376
377 wzPastRoot = PathSkipPastRoot(sczPath, NULL, NULL, NULL);
378 DirExitOnNull(wzPastRoot, hr, E_INVALIDARG, "Full path was not rooted: %ls", sczPath);
369 379
370 while (wzPath && *wzPath && ::RemoveDirectoryW(wzPath)) 380 cchRoot = wzPastRoot - sczPath;
381
382 while (sczPath && sczPath[cchRoot] && ::RemoveDirectoryW(sczPath))
371 { 383 {
372 ++cDeletedDirs; 384 ++cDeletedDirs;
373 385
374 HRESULT hr = PathGetParentPath(wzPath, &sczPath); 386 hr = PathGetParentPath(sczPath, &sczPath, &cchRoot);
375 DirExitOnFailure(hr, "Failed to get parent directory for path: %ls", wzPath); 387 DirExitOnFailure(hr, "Failed to get parent directory for path: %ls", sczPath);
376
377 wzPath = sczPath;
378 } 388 }
379 389
380LExit: 390LExit: