store abspath to the lock file
Avoids problems if the program chdirs
This commit is contained in:
parent
b0626230b7
commit
e2b4861bff
1 changed files with 9 additions and 9 deletions
|
@ -114,7 +114,8 @@ sideLockFile lockfile = do
|
||||||
-- this can't be done and stale locks may persist.
|
-- this can't be done and stale locks may persist.
|
||||||
tryLock :: LockFile -> IO (Maybe LockHandle)
|
tryLock :: LockFile -> IO (Maybe LockHandle)
|
||||||
tryLock lockfile = trySideLock lockfile $ \sidelock -> do
|
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)
|
setFileMode tmp (combineModes readModes)
|
||||||
hPutStr h . show =<< mkPidLock
|
hPutStr h . show =<< mkPidLock
|
||||||
hClose h
|
hClose h
|
||||||
|
@ -122,13 +123,13 @@ tryLock lockfile = trySideLock lockfile $ \sidelock -> do
|
||||||
let failedlock = do
|
let failedlock = do
|
||||||
dropLock $ LockHandle tmp st sidelock
|
dropLock $ LockHandle tmp st sidelock
|
||||||
return Nothing
|
return Nothing
|
||||||
let tooklock = return $ Just $ LockHandle lockfile st sidelock
|
let tooklock = return $ Just $ LockHandle lockfile' st sidelock
|
||||||
ifM (linkToLock sidelock tmp lockfile)
|
ifM (linkToLock sidelock tmp lockfile')
|
||||||
( do
|
( do
|
||||||
nukeFile tmp
|
nukeFile tmp
|
||||||
tooklock
|
tooklock
|
||||||
, do
|
, do
|
||||||
v <- readPidLock lockfile
|
v <- readPidLock lockfile'
|
||||||
hn <- getHostName
|
hn <- getHostName
|
||||||
case v of
|
case v of
|
||||||
Just pl | isJust sidelock && hn == lockingHost pl -> do
|
Just pl | isJust sidelock && hn == lockingHost pl -> do
|
||||||
|
@ -137,7 +138,7 @@ tryLock lockfile = trySideLock lockfile $ \sidelock -> do
|
||||||
-- the pidlock was taken on,
|
-- the pidlock was taken on,
|
||||||
-- we know that the pidlock is
|
-- we know that the pidlock is
|
||||||
-- stale, and can take it over.
|
-- stale, and can take it over.
|
||||||
rename tmp lockfile
|
rename tmp lockfile'
|
||||||
tooklock
|
tooklock
|
||||||
_ -> failedlock
|
_ -> failedlock
|
||||||
)
|
)
|
||||||
|
@ -167,7 +168,6 @@ linkToLock (Just _) src dest = do
|
||||||
, fileMode x == fileMode y
|
, fileMode x == fileMode y
|
||||||
, fileOwner x == fileOwner y
|
, fileOwner x == fileOwner y
|
||||||
, fileGroup x == fileGroup y
|
, fileGroup x == fileGroup y
|
||||||
, specialDeviceID x == specialDeviceID y
|
|
||||||
, fileSize x == fileSize y
|
, fileSize x == fileSize y
|
||||||
, modificationTime x == modificationTime y
|
, modificationTime x == modificationTime y
|
||||||
, isRegularFile x == isRegularFile 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
|
-- Checks that the lock file still exists, and is the same file that was
|
||||||
-- locked to get the LockHandle.
|
-- locked to get the LockHandle.
|
||||||
checkSaneLock :: LockFile -> LockHandle -> IO Bool
|
checkSaneLock :: LockFile -> LockHandle -> IO Bool
|
||||||
checkSaneLock lockfile (LockHandle _ st _) =
|
checkSaneLock lockfile (LockHandle f st _) =
|
||||||
go =<< catchMaybeIO (getFileStatus lockfile)
|
go =<< catchMaybeIO (getFileStatus lockfile)
|
||||||
where
|
where
|
||||||
go Nothing = return False
|
go Nothing = return False
|
||||||
go (Just st') = do
|
go (Just st') = return $
|
||||||
return $ deviceID st == deviceID st' && fileID st == fileID st'
|
deviceID st == deviceID st' && fileID st == fileID st'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue