When a transfer is already being run by another process, proceed on to the next file, rather than dying.

This commit is contained in:
Joey Hess 2013-07-17 15:54:01 -04:00
parent 1fe486813f
commit 7afd92d083
2 changed files with 23 additions and 12 deletions

View file

@ -103,11 +103,13 @@ download u key = runTransfer (Transfer Download u key)
{- Runs a transfer action. Creates and locks the lock file while the {- Runs a transfer action. Creates and locks the lock file while the
- action is running, and stores info in the transfer information - action is running, and stores info in the transfer information
- file. Will throw an error if the transfer is already in progress. - file.
- -
- If the transfer action returns False, the transfer info is - If the transfer action returns False, the transfer info is
- left in the failedTransferDir. - left in the failedTransferDir.
- -
- If the transfer is already in progress, returns False.
-
- An upload can be run from a read-only filesystem, and in this case - An upload can be run from a read-only filesystem, and in this case
- no transfer information or lock file is used. - no transfer information or lock file is used.
-} -}
@ -116,11 +118,14 @@ runTransfer t file shouldretry a = do
info <- liftIO $ startTransferInfo file info <- liftIO $ startTransferInfo file
(meter, tfile, metervar) <- mkProgressUpdater t info (meter, tfile, metervar) <- mkProgressUpdater t info
mode <- annexFileMode mode <- annexFileMode
fd <- liftIO $ prep tfile mode info (fd, cantransfer) <- liftIO $ prep tfile mode info
ok <- retry info metervar $ if cantransfer
bracketIO (return fd) (cleanup tfile) (const $ a meter) then do
unless ok $ recordFailedTransfer t info ok <- retry info metervar $
return ok bracketIO (return fd) (cleanup tfile) (const $ a meter)
unless ok $ recordFailedTransfer t info
return ok
else return False
where where
prep tfile mode info = do prep tfile mode info = do
#ifndef __WINDOWS__ #ifndef __WINDOWS__
@ -128,18 +133,22 @@ runTransfer t file shouldretry a = do
openFd (transferLockFile tfile) ReadWrite (Just mode) openFd (transferLockFile tfile) ReadWrite (Just mode)
defaultFileFlags { trunc = True } defaultFileFlags { trunc = True }
case mfd of case mfd of
Nothing -> return mfd Nothing -> return (mfd, True)
Just fd -> do Just fd -> do
locked <- catchMaybeIO $ locked <- catchMaybeIO $
setLock fd (WriteLock, AbsoluteSeek, 0, 0) setLock fd (WriteLock, AbsoluteSeek, 0, 0)
when (isNothing locked) $ if isNothing locked
error "transfer already in progress" then do
void $ tryIO $ writeTransferInfoFile info tfile hPutStrLn stderr "transfer already in progress"
return mfd return (Nothing, False)
else do
void $ tryIO $ writeTransferInfoFile info tfile
return (mfd, True)
#else #else
catchMaybeIO $ do mfd <- catchMaybeIO $ do
writeFile (transferLockFile tfile) "" writeFile (transferLockFile tfile) ""
writeTransferInfoFile info tfile writeTransferInfoFile info tfile
return (mfd, True)
#endif #endif
cleanup _ Nothing = noop cleanup _ Nothing = noop
cleanup tfile (Just fd) = do cleanup tfile (Just fd) = do

2
debian/changelog vendored
View file

@ -9,6 +9,8 @@ git-annex (4.20130710) UNRELEASED; urgency=low
* uninit: Preserve .git/annex/objects at the end, if it still * uninit: Preserve .git/annex/objects at the end, if it still
has content, so that old versions of files and deleted files has content, so that old versions of files and deleted files
are not deleted. Print a message with some suggested actions. are not deleted. Print a message with some suggested actions.
* When a transfer is already being run by another process,
proceed on to the next file, rather than dying.
-- Joey Hess <joeyh@debian.org> Tue, 09 Jul 2013 19:17:13 -0400 -- Joey Hess <joeyh@debian.org> Tue, 09 Jul 2013 19:17:13 -0400