summaryrefslogtreecommitdiff
path: root/Annex/ReplaceFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-12 13:00:03 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-12 13:00:08 -0400
commit67fd45c894d48d5168faeff4c419cce8fb2fe43f (patch)
tree452ee8423f3dede5e409f950e66d68cf130ba4c7 /Annex/ReplaceFile.hs
parentda66a6384e1958994e979eeccc3f6f10a51205c6 (diff)
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.
Diffstat (limited to 'Annex/ReplaceFile.hs')
-rw-r--r--Annex/ReplaceFile.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Annex/ReplaceFile.hs b/Annex/ReplaceFile.hs
index 8776762e9..8cb0cc6da 100644
--- a/Annex/ReplaceFile.hs
+++ b/Annex/ReplaceFile.hs
@@ -30,14 +30,16 @@ replaceFileOr :: FilePath -> (FilePath -> Annex ()) -> (FilePath -> Annex ()) ->
replaceFileOr file action rollback = do
tmpdir <- fromRepo gitAnnexTmpMiscDir
void $ createAnnexDirectory tmpdir
- bracket (liftIO $ setup tmpdir) rollback $ \tmpfile -> do
- action tmpfile
- liftIO $ catchIO (rename tmpfile file) (fallback tmpfile)
+ tmpfile <- liftIO $ setup tmpdir
+ go tmpfile `catchNonAsync` (const $ rollback tmpfile)
where
setup tmpdir = do
(tmpfile, h) <- openTempFileWithDefaultPermissions tmpdir "tmp"
hClose h
return tmpfile
+ go tmpfile = do
+ action tmpfile
+ liftIO $ catchIO (rename tmpfile file) (fallback tmpfile)
fallback tmpfile _ = do
createDirectoryIfMissing True $ parentDir file
moveFile tmpfile file