summaryrefslogtreecommitdiff
path: root/Annex/Content.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-10 20:24:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-10 20:57:28 -0400
commit49d2177d51b95b4a01c05ee07e166e93751b4c51 (patch)
treeb818865e5a924dc90bf0a79608351b1aeffe458a /Annex/Content.hs
parenta71c03bc5162916853ff520d5c7c89e849c6a047 (diff)
factored out some useful error catching methods
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r--Annex/Content.hs12
1 files changed, 5 insertions, 7 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index f50616af9..7586bb96f 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -83,19 +83,17 @@ lockContent key a = do
unlock (Just l) = closeFd l
openForLock :: FilePath -> Bool -> IO (Maybe Fd)
-openForLock file writelock = bracket_ prep cleanup $
- catch (Just <$> openFd file mode Nothing defaultFileFlags)
- (const $ return Nothing)
+openForLock file writelock = bracket_ prep cleanup go
where
+ go = catchMaybeIO $ openFd file mode Nothing defaultFileFlags
mode = if writelock then ReadWrite else ReadOnly
{- Since files are stored with the write bit disabled,
- have to fiddle with permissions to open for an
- - exclusive lock. flock locking would avoid this,
- - but -}
- prep = forwritelock $ allowWrite file
- cleanup = forwritelock $ preventWrite file
+ - exclusive lock. -}
forwritelock a =
when writelock $ whenM (doesFileExist file) $ a
+ prep = forwritelock $ allowWrite file
+ cleanup = forwritelock $ preventWrite file
{- Calculates the relative path to use to link a file to a key. -}
calcGitLink :: FilePath -> Key -> Annex FilePath