direct: Fix ugly warning messages.

replaceFileOr was broken and ran the rollback action always.
Luckily, for replaceFile, the rollback action was safe to run, since it
just nuked a temp file that had already been moved into place.

However, when `git annex direct` used replaeFileOr, its rollback printed a
scary message:

  /home/joey/tmp/rrrr/.git/annex/misctmp/tmp32268: rename: does not exist (No such file or directory)

There was actually no bad result though.
This commit is contained in:
Joey Hess 2014-08-12 13:00:03 -04:00
parent 7285896996
commit d8be828734
2 changed files with 6 additions and 3 deletions

View file

@ -30,14 +30,16 @@ replaceFileOr :: FilePath -> (FilePath -> Annex ()) -> (FilePath -> Annex ()) ->
replaceFileOr file action rollback = do replaceFileOr file action rollback = do
tmpdir <- fromRepo gitAnnexTmpMiscDir tmpdir <- fromRepo gitAnnexTmpMiscDir
void $ createAnnexDirectory tmpdir void $ createAnnexDirectory tmpdir
bracket (liftIO $ setup tmpdir) rollback $ \tmpfile -> do tmpfile <- liftIO $ setup tmpdir
action tmpfile go tmpfile `catchNonAsync` (const $ rollback tmpfile)
liftIO $ catchIO (rename tmpfile file) (fallback tmpfile)
where where
setup tmpdir = do setup tmpdir = do
(tmpfile, h) <- openTempFileWithDefaultPermissions tmpdir "tmp" (tmpfile, h) <- openTempFileWithDefaultPermissions tmpdir "tmp"
hClose h hClose h
return tmpfile return tmpfile
go tmpfile = do
action tmpfile
liftIO $ catchIO (rename tmpfile file) (fallback tmpfile)
fallback tmpfile _ = do fallback tmpfile _ = do
createDirectoryIfMissing True $ parentDir file createDirectoryIfMissing True $ parentDir file
moveFile tmpfile file moveFile tmpfile file

1
debian/changelog vendored
View file

@ -30,6 +30,7 @@ git-annex (5.20140718) UNRELEASED; urgency=medium
* Windows: Now uses actual inode equivilants in new direct mode * Windows: Now uses actual inode equivilants in new direct mode
repositories, for safer detection of eg, renaming of files with the same repositories, for safer detection of eg, renaming of files with the same
size and mtime. size and mtime.
* direct: Fix ugly warning messages.
-- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2014 14:41:26 -0400 -- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2014 14:41:26 -0400