aboutsummaryrefslogtreecommitdiff
path: root/Annex/Content.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-03-14 17:43:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-03-14 17:43:34 -0400
commit60ab3d84e188b8dd3a284d962df25bbee41ff1cb (patch)
tree768d4f632bab0152dbc1ca72f81fc3b9c7915c0a /Annex/Content.hs
parenta4f72c9625486786a4549cf4db1b542ea89da7c7 (diff)
added ifM and nuked 11 lines of code
no behavior changes
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r--Annex/Content.hs35
1 files changed, 17 insertions, 18 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index ccaff5c56..fad5f5134 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -150,16 +150,16 @@ prepTmp key = do
getViaTmpUnchecked :: Key -> (FilePath -> Annex Bool) -> Annex Bool
getViaTmpUnchecked key action = do
tmp <- prepTmp key
- success <- action tmp
- if success
- then do
+ ifM (action tmp)
+ ( do
moveAnnex key tmp
logStatus key InfoPresent
return True
- else do
+ , do
-- the tmp file is left behind, in case caller wants
-- to resume its transfer
return False
+ )
{- Creates a temp file, runs an action on it, and cleans up the temp file. -}
withTmp :: Key -> (FilePath -> Annex a) -> Annex a
@@ -230,15 +230,15 @@ moveAnnex :: Key -> FilePath -> Annex ()
moveAnnex key src = do
dest <- inRepo $ gitAnnexLocation key
let dir = parentDir dest
- e <- liftIO $ doesFileExist dest
- if e
- then liftIO $ removeFile src
- else liftIO $ do
+ liftIO $ ifM (doesFileExist dest)
+ ( removeFile src
+ , do
createDirectoryIfMissing True dir
allowWrite dir -- in case the directory already exists
moveFile src dest
preventWrite dest
preventWrite dir
+ )
withObjectLoc :: Key -> ((FilePath, FilePath) -> Annex a) -> Annex a
withObjectLoc key a = do
@@ -314,12 +314,12 @@ getKeysPresent = liftIO . traverse (2 :: Int) =<< fromRepo gitAnnexObjectDir
saveState :: Bool -> Annex ()
saveState oneshot = do
Annex.Queue.flush False
- unless oneshot $ do
- alwayscommit <- fromMaybe True . Git.configTrue
+ unless oneshot $
+ ifM alwayscommit
+ ( Annex.Branch.commit "update" , Annex.Branch.stage)
+ where
+ alwayscommit = fromMaybe True . Git.configTrue
<$> fromRepo (Git.Config.get "annex.alwayscommit" "")
- if alwayscommit
- then Annex.Branch.commit "update"
- else Annex.Branch.stage
{- Downloads content from any of a list of urls. -}
downloadUrl :: [Url.URLString] -> FilePath -> Annex Bool
@@ -338,10 +338,9 @@ preseedTmp key file = go =<< inAnnex key
ok <- copy
when ok $ liftIO $ allowWrite file
return ok
- copy = do
- present <- liftIO $ doesFileExist file
- if present
- then return True
- else do
+ copy = ifM (liftIO $ doesFileExist file)
+ ( return True
+ , do
s <- inRepo $ gitAnnexLocation key
liftIO $ copyFileExternal s file
+ )