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
- 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
- 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
- no transfer information or lock file is used.
-}
@ -116,11 +118,14 @@ runTransfer t file shouldretry a = do
info <- liftIO $ startTransferInfo file
(meter, tfile, metervar) <- mkProgressUpdater t info
mode <- annexFileMode
fd <- liftIO $ prep tfile mode info
ok <- retry info metervar $
bracketIO (return fd) (cleanup tfile) (const $ a meter)
unless ok $ recordFailedTransfer t info
return ok
(fd, cantransfer) <- liftIO $ prep tfile mode info
if cantransfer
then do
ok <- retry info metervar $
bracketIO (return fd) (cleanup tfile) (const $ a meter)
unless ok $ recordFailedTransfer t info
return ok
else return False
where
prep tfile mode info = do
#ifndef __WINDOWS__
@ -128,18 +133,22 @@ runTransfer t file shouldretry a = do
openFd (transferLockFile tfile) ReadWrite (Just mode)
defaultFileFlags { trunc = True }
case mfd of
Nothing -> return mfd
Nothing -> return (mfd, True)
Just fd -> do
locked <- catchMaybeIO $
setLock fd (WriteLock, AbsoluteSeek, 0, 0)
when (isNothing locked) $
error "transfer already in progress"
void $ tryIO $ writeTransferInfoFile info tfile
return mfd
if isNothing locked
then do
hPutStrLn stderr "transfer already in progress"
return (Nothing, False)
else do
void $ tryIO $ writeTransferInfoFile info tfile
return (mfd, True)
#else
catchMaybeIO $ do
mfd <- catchMaybeIO $ do
writeFile (transferLockFile tfile) ""
writeTransferInfoFile info tfile
return (mfd, True)
#endif
cleanup _ Nothing = noop
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
has content, so that old versions of files and deleted files
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