Avoid deleting temp files when rsync fails.

This commit is contained in:
Joey Hess 2010-12-02 17:51:02 -04:00
parent b9320ee1d5
commit 2fba1ba40d
3 changed files with 16 additions and 12 deletions

25
Core.hs
View file

@ -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

1
debian/changelog vendored
View file

@ -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

View file

@ -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