summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-15 13:38:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-15 13:38:05 -0400
commit6c36d87ceff8b792e1f1a0f6b324e79173cc923c (patch)
treecf686e3db00d4a571412bbadfc91231accac16bc /Annex
parentcfaa1a8fcf522ef3f51bbd2a057e7ab571bcdd1b (diff)
direct: Avoid leaving file content in misctemp if interrupted.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Direct.hs7
-rw-r--r--Annex/ReplaceFile.hs13
2 files changed, 11 insertions, 9 deletions
diff --git a/Annex/Direct.hs b/Annex/Direct.hs
index 374599369..7b91cc342 100644
--- a/Annex/Direct.hs
+++ b/Annex/Direct.hs
@@ -353,11 +353,8 @@ toDirectGen k f = do
void $ addAssociatedFile k f
modifyContent loc $ do
thawContent loc
- replaceFileOr f
- (liftIO . moveFile loc)
- $ \tmp -> do -- rollback
- liftIO (moveFile tmp loc)
- freezeContent loc
+ liftIO (replaceFileFrom loc f)
+ `catchIO` (\_ -> freezeContent loc)
fromdirect loc = do
replaceFile f $
liftIO . void . copyFileExternal loc
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