From 6b0f2d978504da82070523eb6adb0b59f9812e93 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:48:39 -0500 Subject: Add PathSkipPastRoot. --- src/libs/dutil/WixToolset.DUtil/dirutil.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/libs/dutil/WixToolset.DUtil/dirutil.cpp') 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( __in DWORD /*dwFlags*/ ) { + HRESULT hr = S_OK; DWORD cDeletedDirs = 0; LPWSTR sczPath = NULL; + LPCWSTR wzPastRoot = NULL; + SIZE_T cchRoot = 0; + + // Make sure the path is normalized and prefixed. + hr = PathExpand(&sczPath, wzPath, PATH_EXPAND_FULLPATH); + DirExitOnFailure(hr, "Failed to get full path for: %ls", wzPath); + + wzPastRoot = PathSkipPastRoot(sczPath, NULL, NULL, NULL); + DirExitOnNull(wzPastRoot, hr, E_INVALIDARG, "Full path was not rooted: %ls", sczPath); - while (wzPath && *wzPath && ::RemoveDirectoryW(wzPath)) + cchRoot = wzPastRoot - sczPath; + + while (sczPath && sczPath[cchRoot] && ::RemoveDirectoryW(sczPath)) { ++cDeletedDirs; - HRESULT hr = PathGetParentPath(wzPath, &sczPath); - DirExitOnFailure(hr, "Failed to get parent directory for path: %ls", wzPath); - - wzPath = sczPath; + hr = PathGetParentPath(sczPath, &sczPath, &cchRoot); + DirExitOnFailure(hr, "Failed to get parent directory for path: %ls", sczPath); } LExit: -- cgit v1.2.3-55-g6feb