From c696d8df315b7837265c2048c3f375dc59c54c1c Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Tue, 18 Aug 2026 23:02:07 +0100 Subject: [PATCH] Fix renameFileWithRetry leaving temporary files after copying (cherry picked from commit 5078e7d6a1b63e69a0ac03742f26f53f2eb8a679) --- Cabal-syntax/src/Distribution/Utils/Generic.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Utils/Generic.hs b/Cabal-syntax/src/Distribution/Utils/Generic.hs index f6e43ab8bfd..e0ee92ee68d 100644 --- a/Cabal-syntax/src/Distribution/Utils/Generic.hs +++ b/Cabal-syntax/src/Distribution/Utils/Generic.hs @@ -211,7 +211,7 @@ renameFileWithRetry srcPath targetPath = -- UnsupportedOperation means EXDEV from rename(2) with source and target -- on different devices. In such case we resort to copying instead of renaming. | ioeGetErrorType exception == UnsupportedOperation = - copyFile srcPath targetPath `Exception.catch` retryCopy (retriesLeft - 1) + retryCopy retriesLeft exception | otherwise = do -- Wait 1ms between retries: maybe device is busy, maybe antivirus locked srcPath. threadDelay 1000 @@ -222,7 +222,7 @@ renameFileWithRetry srcPath targetPath = retryCopy retriesLeft _ = do -- Wait 1ms between retries: maybe device is busy, maybe antivirus locked srcPath. threadDelay 1000 - copyFile srcPath targetPath `Exception.catch` retryCopy retriesLeft + copyFile srcPath targetPath `Exception.catch` retryCopy (retriesLeft - 1) -- It's nice to clean up, but not critical, so ignoring any exceptions. removeFile srcPath `Exception.catch` (\(_ :: IOException) -> pure ())