aboutsummaryrefslogtreecommitdiff
path: root/Annex/Content.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-11-29 15:49:05 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-11-29 16:40:32 -0400
commit3b3f7512f6d0b91de21f6fcc4aba8897174bc4a8 (patch)
tree44c85fda3d6a35d62b00cca26bf6acaf474133c2 /Annex/Content.hs
parentb7178922644c813a2cb69c185ca751aa234fa05b (diff)
youtube-dl working
Including resuming and cleanup of incomplete downloads. Still todo: --fast, --relaxed, importfeed, disk reserve checking, quvi code cleanup. This commit was sponsored by Anthony DeRobertis on Patreon.
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r--Annex/Content.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 5b11c7eb1..0899a12ab 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -1017,14 +1017,15 @@ pruneTmpWorkDirBefore f action = do
{- Runs an action, passing it a temporary work directory where
- it can write files while receiving the content of a key.
-
- - On exception, the temporary work directory is left, so resumes can
- - use it.
+ - On exception, or when the action returns a Left value,
+ - the temporary work directory is left, so resumes can use it.
-}
-withTmpWorkDir :: Key -> (FilePath -> Annex a) -> Annex a
-withTmpWorkDir key action = withTmp key $ \obj -> do
+withTmpWorkDir :: Key -> (FilePath -> Annex (Either a b)) -> Annex (Either a b)
+withTmpWorkDir key action = do
-- Create the object file if it does not exist. This way,
-- staleKeysPrune only has to look for object files, and can
-- clean up gitAnnexTmpWorkDir for those it finds.
+ obj <- prepTmp key
unlessM (liftIO $ doesFileExist obj) $ do
liftIO $ writeFile obj ""
setAnnexFilePerm obj
@@ -1032,7 +1033,9 @@ withTmpWorkDir key action = withTmp key $ \obj -> do
liftIO $ createDirectoryIfMissing True tmpdir
setAnnexDirPerm tmpdir
res <- action tmpdir
- liftIO $ removeDirectoryRecursive tmpdir
+ case res of
+ Right _ -> liftIO $ removeDirectoryRecursive tmpdir
+ Left _ -> noop
return res
{- Finds items in the first, smaller list, that are not