From 6c36d87ceff8b792e1f1a0f6b324e79173cc923c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 15 Aug 2014 13:38:05 -0400 Subject: direct: Avoid leaving file content in misctemp if interrupted. --- Annex/Direct.hs | 7 ++----- Annex/ReplaceFile.hs | 13 +++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'Annex') 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 -- cgit v1.2.3