From 2113f2bedbdf5c2f8fb21fc5dfacc6ddc7379fe7 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 12 Apr 2021 15:08:52 -0700 Subject: [PATCH] Make FileCopyUsingHandlesWithProgress more like MoveFileWithProgress FileCopyUsingHandlesWithProgress now returns ERROR_REQUEST_ABORTED as an HRESULT when canceled or stopping rather than return success. --- src/dutil/fileutil.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/dutil/fileutil.cpp b/src/dutil/fileutil.cpp index 06a44b4..cb67813 100644 --- a/src/dutil/fileutil.cpp +++ b/src/dutil/fileutil.cpp @@ -1120,7 +1120,6 @@ extern "C" HRESULT DAPI FileCopyUsingHandlesWithProgress( ) { HRESULT hr = S_OK; - BOOL fStop = FALSE; BOOL fCanceled = FALSE; DWORD64 cbTotalCopied = 0; BYTE rgbData[64 * 1024]; @@ -1147,12 +1146,10 @@ extern "C" HRESULT DAPI FileCopyUsingHandlesWithProgress( case PROGRESS_CANCEL: fCanceled = TRUE; - fStop = TRUE; - break; + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_REQUEST_ABORTED)); case PROGRESS_STOP: - fStop = TRUE; - break; + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_REQUEST_ABORTED)); case PROGRESS_QUIET: lpProgressRoutine = NULL; @@ -1173,7 +1170,7 @@ extern "C" HRESULT DAPI FileCopyUsingHandlesWithProgress( } // Copy with progress. - while (!fStop && (0 == cbCopy || cbTotalCopied < cbCopy)) + while (0 == cbCopy || cbTotalCopied < cbCopy) { cbRead = static_cast((0 == cbCopy) ? countof(rgbData) : min(countof(rgbData), cbCopy - cbTotalCopied)); if (!::ReadFile(hSource, rgbData, cbRead, &cbRead, NULL)) @@ -1199,12 +1196,10 @@ extern "C" HRESULT DAPI FileCopyUsingHandlesWithProgress( case PROGRESS_CANCEL: fCanceled = TRUE; - fStop = TRUE; - break; + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_REQUEST_ABORTED)); case PROGRESS_STOP: - fStop = TRUE; - break; + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_REQUEST_ABORTED)); case PROGRESS_QUIET: lpProgressRoutine = NULL; @@ -1214,7 +1209,7 @@ extern "C" HRESULT DAPI FileCopyUsingHandlesWithProgress( } else { - fStop = TRUE; + break; } }