added ifM and nuked 11 lines of code

no behavior changes
This commit is contained in:
Joey Hess 2012-03-14 17:43:34 -04:00
parent a4f72c9625
commit 60ab3d84e1
17 changed files with 151 additions and 162 deletions

View file

@ -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
)