From 6b986240d9397563a888e40edc3c11857b36a4c3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Jun 2017 14:21:43 -0400 Subject: Fix bug that prevented transfer locks from working when run on SMB or other filesystem that does not support fcntl locks and hard links. This commit was sponsored by Ethan Aubin. --- Utility/LockFile/PidLock.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Utility/LockFile/PidLock.hs') diff --git a/Utility/LockFile/PidLock.hs b/Utility/LockFile/PidLock.hs index 23560fa57..0db9d1f3f 100644 --- a/Utility/LockFile/PidLock.hs +++ b/Utility/LockFile/PidLock.hs @@ -122,18 +122,21 @@ tryLock lockfile = trySideLock lockfile $ \sidelock -> do setFileMode tmp (combineModes readModes) hPutStr h . show =<< mkPidLock hClose h - st <- getFileStatus tmp - let failedlock = do + let failedlock st = do dropLock $ LockHandle tmp st sidelock return Nothing - let tooklock = return $ Just $ LockHandle lockfile' st sidelock + let tooklock st = return $ Just $ LockHandle lockfile' st sidelock ifM (linkToLock sidelock tmp lockfile') ( do nukeFile tmp - tooklock + -- May not have made a hard link, so stat + -- the lockfile + lckst <- getFileStatus lockfile' + tooklock lckst , do v <- readPidLock lockfile' hn <- getHostName + tmpst <- getFileStatus tmp case v of Just pl | isJust sidelock && hn == lockingHost pl -> do -- Since we have the sidelock, @@ -142,8 +145,8 @@ tryLock lockfile = trySideLock lockfile $ \sidelock -> do -- we know that the pidlock is -- stale, and can take it over. rename tmp lockfile' - tooklock - _ -> failedlock + tooklock tmpst + _ -> failedlock tmpst ) -- Linux's open(2) man page recommends linking a pid lock into place, -- cgit v1.2.3