diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-05-12 19:36:16 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-05-12 19:36:16 -0400 |
commit | 6105e33c7f72c7a81bb78f06581cbf0a67594e6d (patch) | |
tree | db682343025f99b84b032d2b7ec075e56645db18 /Annex | |
parent | b38e187c0bfd6f4bcef6c235c555752aca193edc (diff) |
convert to using Utility.Lockfile for transfer lock files
Should be no behavior changes, just simplified code.
The only actual difference is it doesn't truncate the lock file.
I think that was a holdover from when transfer info was written to the lock
file.
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/Transfer.hs | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/Annex/Transfer.hs b/Annex/Transfer.hs index cf04810da..1d7f2b98f 100644 --- a/Annex/Transfer.hs +++ b/Annex/Transfer.hs @@ -23,9 +23,7 @@ import Logs.Transfer as X import Annex.Notification as X import Annex.Perms import Utility.Metered -#ifdef mingw32_HOST_OS import Utility.LockFile -#endif import Control.Concurrent @@ -70,14 +68,14 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do info <- liftIO $ startTransferInfo file (meter, tfile, metervar) <- mkProgressUpdater t info mode <- annexFileMode - (fd, inprogress) <- liftIO $ prep tfile mode info + (lck, inprogress) <- liftIO $ prep tfile mode info if inprogress && not ignorelock then do showNote "transfer already in progress" return False else do ok <- retry info metervar $ bracketIO - (return fd) + (return lck) (cleanup tfile) (const $ transferaction meter) transferobserver ok t info @@ -85,25 +83,17 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do where #ifndef mingw32_HOST_OS prep tfile mode info = do - mfd <- catchMaybeIO $ - openFd (transferLockFile tfile) ReadWrite (Just mode) - defaultFileFlags { trunc = True } - case mfd of - Nothing -> return (Nothing, False) - Just fd -> do - setFdOption fd CloseOnExec True - locked <- catchMaybeIO $ - setLock fd (WriteLock, AbsoluteSeek, 0, 0) - if isNothing locked - then do - closeFd fd - return (Nothing, True) - else do - void $ tryIO $ writeTransferInfoFile info tfile - return (mfd, False) + let lck = transferLockFile tfile + r <- tryLockExclusive (Just mode) lck + case r of + Nothing -> return (Nothing, True) + Just lockhandle -> do + void $ tryIO $ writeTransferInfoFile info tfile + return (Just lockhandle, False) #else prep tfile _mode info = do - v <- catchMaybeIO $ lockExclusive (transferLockFile tfile) + let lck = transferLockFile tfile + v <- catchMaybeIO $ lockExclusive lck case v of Nothing -> return (Nothing, False) Just Nothing -> return (Nothing, True) @@ -113,10 +103,11 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do #endif cleanup _ Nothing = noop cleanup tfile (Just lockhandle) = do + let lck = transferLockFile tfile void $ tryIO $ removeFile tfile #ifndef mingw32_HOST_OS - void $ tryIO $ removeFile $ transferLockFile tfile - closeFd lockhandle + void $ tryIO $ removeFile lck + dropLock lockhandle #else {- Windows cannot delete the lockfile until the lock - is closed. So it's possible to race with another @@ -124,7 +115,7 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do - so ignore failure to remove. -} dropLock lockhandle - void $ tryIO $ removeFile $ transferLockFile tfile + void $ tryIO $ removeFile lck #endif retry oldinfo metervar run = do v <- tryNonAsync run |