From 2c62f8e63d000695037352c2c2bda55983830e46 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 28 Jun 2018 12:58:11 -0400 Subject: [PATCH] remove empty tmp workdir on failure No point in keeping an empty tmp workdir around. The associated tmp object file is retained even if empty, didn't want to deal with any possible races with something else downloading to that file at the same time this would check if it's empty. Anyhow, temp object files are normally retained, and this will get cleaned out the same way those do, by dropunused. --- Annex/Content.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Annex/Content.hs b/Annex/Content.hs index cc0a0b3a6e..2363793bcc 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -1060,8 +1060,12 @@ 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. - + - Preserves the invariant that the workdir never exists without the + - content file, by creating an empty content file first. + - - On exception, or when the action returns Nothing, - - the temporary work directory is left, so resumes can use it. + - the temporary work directory is retained (unless + - empty), so anything in it can be used on resume. -} withTmpWorkDir :: Key -> (FilePath -> Annex (Maybe a)) -> Annex (Maybe a) withTmpWorkDir key action = do @@ -1078,7 +1082,7 @@ withTmpWorkDir key action = do res <- action tmpdir case res of Just _ -> liftIO $ removeDirectoryRecursive tmpdir - Nothing -> noop + Nothing -> liftIO $ void $ tryIO $ removeDirectory tmpdir return res {- Finds items in the first, smaller list, that are not