diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-11-16 15:25:04 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-11-16 15:25:04 -0400 |
commit | 24cdd3abc3170f25913e49e8fb6ccf7b0d23a770 (patch) | |
tree | 9407cb5fdfe283dbbe631ba3eb1ba6760cd84c82 /Utility | |
parent | e316eac6c816111c11280aab79e9a058f86d902b (diff) |
store abspath to the lock file
Avoids problems if the program chdirs
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/LockFile/PidLock.hs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Utility/LockFile/PidLock.hs b/Utility/LockFile/PidLock.hs index 5d93f16f8..9c70cc05a 100644 --- a/Utility/LockFile/PidLock.hs +++ b/Utility/LockFile/PidLock.hs @@ -114,7 +114,8 @@ sideLockFile lockfile = do -- this can't be done and stale locks may persist. tryLock :: LockFile -> IO (Maybe LockHandle) tryLock lockfile = trySideLock lockfile $ \sidelock -> do - (tmp, h) <- openTempFile (takeDirectory lockfile) "locktmp" + lockfile' <- absPath lockfile + (tmp, h) <- openTempFile (takeDirectory lockfile') "locktmp" setFileMode tmp (combineModes readModes) hPutStr h . show =<< mkPidLock hClose h @@ -122,13 +123,13 @@ tryLock lockfile = trySideLock lockfile $ \sidelock -> do let failedlock = do dropLock $ LockHandle tmp st sidelock return Nothing - let tooklock = return $ Just $ LockHandle lockfile st sidelock - ifM (linkToLock sidelock tmp lockfile) + let tooklock = return $ Just $ LockHandle lockfile' st sidelock + ifM (linkToLock sidelock tmp lockfile') ( do nukeFile tmp tooklock , do - v <- readPidLock lockfile + v <- readPidLock lockfile' hn <- getHostName case v of Just pl | isJust sidelock && hn == lockingHost pl -> do @@ -137,7 +138,7 @@ tryLock lockfile = trySideLock lockfile $ \sidelock -> do -- the pidlock was taken on, -- we know that the pidlock is -- stale, and can take it over. - rename tmp lockfile + rename tmp lockfile' tooklock _ -> failedlock ) @@ -167,7 +168,6 @@ linkToLock (Just _) src dest = do , fileMode x == fileMode y , fileOwner x == fileOwner y , fileGroup x == fileGroup y - , specialDeviceID x == specialDeviceID y , fileSize x == fileSize y , modificationTime x == modificationTime y , isRegularFile x == isRegularFile y @@ -231,9 +231,9 @@ checkLocked lockfile = conv <$> getLockStatus lockfile -- Checks that the lock file still exists, and is the same file that was -- locked to get the LockHandle. checkSaneLock :: LockFile -> LockHandle -> IO Bool -checkSaneLock lockfile (LockHandle _ st _) = +checkSaneLock lockfile (LockHandle f st _) = go =<< catchMaybeIO (getFileStatus lockfile) where go Nothing = return False - go (Just st') = do - return $ deviceID st == deviceID st' && fileID st == fileID st' + go (Just st') = return $ + deviceID st == deviceID st' && fileID st == fileID st' |