aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/dirutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dirutil.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
index 2c02225d..8c7ef461 100644
--- a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
@@ -17,6 +17,8 @@
17#define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) 17#define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__)
18#define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__) 18#define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__)
19#define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__) 19#define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__)
20#define DirExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DIRUTIL, x, b, s, __VA_ARGS__)
21#define DirExitWithPathLastError(x, s, ...) ExitWithPathLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
20 22
21 23
22/******************************************************************* 24/*******************************************************************
@@ -184,13 +186,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
184 186
185 if (-1 == (dwAttrib = ::GetFileAttributesW(wzPath))) 187 if (-1 == (dwAttrib = ::GetFileAttributesW(wzPath)))
186 { 188 {
187 er = ::GetLastError(); 189 DirExitWithPathLastError(hr, "Failed to get attributes for path: %ls", wzPath);
188 if (ERROR_FILE_NOT_FOUND == er) // change "file not found" to "path not found" since we were looking for a directory. 190
189 { 191 ExitFunction1(hr = E_PATHNOTFOUND);
190 er = ERROR_PATH_NOT_FOUND;
191 }
192 hr = HRESULT_FROM_WIN32(er);
193 DirExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath);
194 } 192 }
195 193
196 if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) 194 if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)
@@ -199,7 +197,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
199 { 197 {
200 if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL)) 198 if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL))
201 { 199 {
202 DirExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath); 200 DirExitWithPathLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath);
201
202 ExitFunction1(hr = E_PATHNOTFOUND);
203 } 203 }
204 } 204 }
205 205
@@ -245,9 +245,12 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
245 hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call 245 hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call
246 if (FAILED(hr)) 246 if (FAILED(hr))
247 { 247 {
248 // if we failed to delete a subdirectory, keep trying to finish any remaining files 248 // if we failed to delete a subdirectory, keep trying to finish any remaining files
249 ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete); 249 if (E_PATHNOTFOUND != hr)
250 hr = S_OK; 250 {
251 ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete);
252 }
253 hr = S_OK;
251 } 254 }
252 } 255 }
253 else if (fDeleteFiles) // this is a file, just delete it 256 else if (fDeleteFiles) // this is a file, just delete it
@@ -256,7 +259,8 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
256 { 259 {
257 if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL)) 260 if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL))
258 { 261 {
259 DirExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete); 262 DirExitWithPathLastError(hr, "Failed to remove attributes from file: %ls", sczDelete);
263 continue;
260 } 264 }
261 } 265 }
262 266
@@ -280,7 +284,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
280 } 284 }
281 else 285 else
282 { 286 {
283 DirExitWithLastError(hr, "Failed to delete file: %ls", sczDelete); 287 DirExitWithPathLastError(hr, "Failed to delete file: %ls", sczDelete);
284 } 288 }
285 } 289 }
286 } 290 }
@@ -308,13 +312,21 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
308 } 312 }
309 } 313 }
310 314
315 if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
316 {
317 ExitFunction1(hr = E_PATHNOTFOUND);
318 }
319 else if (HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) == hr && !fDeleteFiles && !fRecurse)
320 {
321 ExitFunction();
322 }
323
311 DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath); 324 DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath);
312 } 325 }
313 } 326 }
314 else 327 else
315 { 328 {
316 hr = E_UNEXPECTED; 329 DirExitWithRootFailure(hr, E_UNEXPECTED, "Directory delete cannot delete file: %ls", wzPath);
317 DirExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath);
318 } 330 }
319 331
320 Assert(S_OK == hr); 332 Assert(S_OK == hr);