moveFile on windows forgot to delete src file in fallback case
authorJoey Hess <joeyh@joeyh.name>
Fri, 30 May 2025 17:18:26 +0000 (13:18 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 30 May 2025 17:18:26 +0000 (13:18 -0400)
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
Utility/MoveFile.hs

index 5bc38ba826ce4b06efb2b2b101daa58d001fd334..9b7ddf6c5ecfbd3495c50efee26621525a898d56 100644 (file)
--- 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 <id@joeyh.name>  Thu, 22 May 2025 12:43:38 -0400
 
index 54e156920bb94bf55c2c1e5a84f667a76ec70d1e..e327e0b4f176885be2408e748f11b8f764a101a7 100644 (file)
@@ -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