diff options
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r-- | Annex/Content.hs | 35 |
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 + ) |