From b111009868090d5546ab695e157d48dda4c6a2e1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 30 May 2025 13:18:26 -0400 Subject: [PATCH] moveFile on windows forgot to delete src file in fallback case This dates back to commit 625303226dc94c2f35a5a4835b7c53c582014643, where a cross-device moveFile on Windows was made to fall back to copying to the destination, but forgot to delete the source file. Should fix the following test suite failure on Windows: import: FAIL (2.52s) .\Test\Framework.hs:383: C:\Users\RUNNER~1\AppData\Local\Temp\importtest.0\import1\f exists unexpectedly Use -p '/import/' to rerun this test only. Which was seen here, running the test suite in the github action environment. https://github.com/psychoinformatics-de/git-annex-wheel/issues/5 --- CHANGELOG | 2 ++ Utility/MoveFile.hs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 5bc38ba826..9b7ddf6c5e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,8 @@ git-annex (10.20250521) UNRELEASED; urgency=medium entering an adjusted branch. * map: Support --json option. * map: Improve display of remote names. + * Windows: Fix duplicate file bug that could occur when files were + supposed to be moved across devices. -- Joey Hess Thu, 22 May 2025 12:43:38 -0400 diff --git a/Utility/MoveFile.hs b/Utility/MoveFile.hs index 54e156920b..e327e0b4f1 100644 --- a/Utility/MoveFile.hs +++ b/Utility/MoveFile.hs @@ -65,10 +65,12 @@ moveFile src dest = tryIO (renamePath src dest) >>= onrename let (ok, e') = case r of Left err -> (False, err) Right _ -> (True, e) + when ok $ + void $ tryIO $ removeFile src #endif unless ok $ do -- delete any partial - _ <- tryIO $ removeFile tmp + void $ tryIO $ removeFile tmp throwM e' #ifndef mingw32_HOST_OS