summaryrefslogtreecommitdiff
path: root/Annex
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
parenta71c03bc5162916853ff520d5c7c89e849c6a047 (diff)
factored out some useful error catching methods
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Branch.hs10
-rw-r--r--Annex/Content.hs12
2 files changed, 9 insertions, 13 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index 189289ad3..6c28a0c84 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -295,10 +295,8 @@ setJournalFile file content = do
{- Gets any journalled content for a file in the branch. -}
getJournalFile :: FilePath -> Annex (Maybe String)
-getJournalFile file = do
- g <- gitRepo
- liftIO $ catch (liftM Just . readFileStrict $ journalFile g file)
- (const $ return Nothing)
+getJournalFile file = inRepo $ \g -> catchMaybeIO $
+ readFileStrict $ journalFile g file
{- List of files that have updated content in the journal. -}
getJournalledFiles :: Annex [FilePath]
@@ -308,8 +306,8 @@ getJournalledFiles = map fileJournal <$> getJournalFiles
getJournalFiles :: Annex [FilePath]
getJournalFiles = do
g <- gitRepo
- fs <- liftIO $ catch (getDirectoryContents $ gitAnnexJournalDir g)
- (const $ return [])
+ fs <- liftIO $
+ catchDefaultIO (getDirectoryContents $ gitAnnexJournalDir g) []
return $ filter (`notElem` [".", ".."]) fs
{- Stages the specified journalfiles. -}
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