diff options
author | Joey Hess <joey@kitenet.net> | 2014-08-15 13:38:05 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-08-15 13:38:05 -0400 |
commit | 6c36d87ceff8b792e1f1a0f6b324e79173cc923c (patch) | |
tree | cf686e3db00d4a571412bbadfc91231accac16bc /Annex/ReplaceFile.hs | |
parent | cfaa1a8fcf522ef3f51bbd2a057e7ab571bcdd1b (diff) |
direct: Avoid leaving file content in misctemp if interrupted.
Diffstat (limited to 'Annex/ReplaceFile.hs')
-rw-r--r-- | Annex/ReplaceFile.hs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Annex/ReplaceFile.hs b/Annex/ReplaceFile.hs index 8cb0cc6da..9700d4b60 100644 --- a/Annex/ReplaceFile.hs +++ b/Annex/ReplaceFile.hs @@ -39,7 +39,12 @@ replaceFileOr file action rollback = do return tmpfile go tmpfile = do action tmpfile - liftIO $ catchIO (rename tmpfile file) (fallback tmpfile) - fallback tmpfile _ = do - createDirectoryIfMissing True $ parentDir file - moveFile tmpfile file + liftIO $ replaceFileFrom tmpfile file + +replaceFileFrom :: FilePath -> FilePath -> IO () +replaceFileFrom src dest = go `catchIO` fallback + where + go = moveFile src dest + fallback _ = do + createDirectoryIfMissing True $ parentDir dest + go |