summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-12-02 17:51:02 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-12-02 17:51:02 -0400
commit2fba1ba40d9c3f07f36e68515ceb1031e7983421 (patch)
tree8f88c12a809064f6f7bf09904b58956b0a24ca2b
parentb9320ee1d53bfe72b0fbf7e08c927f5b45bbc5c9 (diff)
Avoid deleting temp files when rsync fails.
-rw-r--r--Core.hs25
-rw-r--r--debian/changelog1
-rw-r--r--git-annex.hs2
3 files changed, 16 insertions, 12 deletions
diff --git a/Core.hs b/Core.hs
index b61d18666..8cdb063c7 100644
--- a/Core.hs
+++ b/Core.hs
@@ -29,7 +29,7 @@ import Messages
{- Runs a list of Annex actions. Catches IO errors and continues
- (but explicitly thrown errors terminate the whole command).
- - Propigates an overall error status at the end.
+ - Runs shutdown and propigates an overall error status at the end.
-}
tryRun :: AnnexState -> [Annex Bool] -> IO ()
tryRun state actions = tryRun' state 0 actions
@@ -42,7 +42,8 @@ tryRun' state errnum (a:as) = do
tryRun' state (errnum + 1) as
Right (True,state') -> tryRun' state' errnum as
Right (False,state') -> tryRun' state' (errnum + 1) as
-tryRun' _ errnum [] =
+tryRun' state errnum [] = do
+ _ <- try $ Annex.run state $ shutdown errnum
when (errnum > 0) $ error $ show errnum ++ " failed"
{- Actions to perform each time ran. -}
@@ -52,20 +53,22 @@ startup = do
return True
{- When git-annex is done, it runs this. -}
-shutdown :: Annex Bool
-shutdown = do
+shutdown :: Integer -> Annex Bool
+shutdown errnum = do
q <- Annex.queueGet
unless (q == GitQueue.empty) $ do
showSideAction "Recording state in git..."
Annex.queueRun
- -- clean up any files left in the temp directory, but leave
- -- the tmp directory itself
- g <- Annex.gitRepo
- let tmp = annexTmpLocation g
- exists <- liftIO $ doesDirectoryExist tmp
- when exists $ liftIO $ removeDirectoryRecursive tmp
- liftIO $ createDirectoryIfMissing True tmp
+ -- If nothing failed, clean up any files left in the temp directory,
+ -- but leave the directory itself. If something failed, temp files
+ -- are left behind to allow resuming on re-run.
+ when (errnum == 0) $ do
+ g <- Annex.gitRepo
+ let tmp = annexTmpLocation g
+ exists <- liftIO $ doesDirectoryExist tmp
+ when exists $ liftIO $ removeDirectoryRecursive tmp
+ liftIO $ createDirectoryIfMissing True tmp
return True
diff --git a/debian/changelog b/debian/changelog
index 5a9d332bc..fb2d2aae2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,7 @@ git-annex (0.11) UNRELEASED; urgency=low
* If available, rsync will be used for file transfers from remote
repositories. This allows resuming interrupted transfers.
* Added remote.annex-rsync-options.
+ * Avoid deleting temp files when rsync fails.
-- Joey Hess <joeyh@debian.org> Thu, 02 Dec 2010 16:54:12 -0400
diff --git a/git-annex.hs b/git-annex.hs
index d111156f0..417d335e1 100644
--- a/git-annex.hs
+++ b/git-annex.hs
@@ -20,4 +20,4 @@ main = do
gitrepo <- Git.repoFromCwd
state <- Annex.new gitrepo allBackends
(configure, actions) <- parseCmd args state
- tryRun state $ [startup, upgrade] ++ configure ++ actions ++ [shutdown]
+ tryRun state $ [startup, upgrade] ++ configure ++ actions