add whenM and unlessM

Just more golfing.. I am pretty sure something in a library somewhere can
do this, but I have been unable to find it.
This commit is contained in:
Joey Hess 2011-05-17 03:10:13 -04:00
parent 75a3f5027f
commit c91929f693
16 changed files with 60 additions and 63 deletions

View file

@ -8,7 +8,6 @@
module Command.Migrate where
import Control.Monad.State (liftIO)
import Control.Monad (unless, when)
import System.Posix.Files
import System.Directory
import System.FilePath
@ -20,6 +19,7 @@ import Locations
import Types
import Content
import Messages
import Utility
import qualified Command.Add
command :: [Command]
@ -63,9 +63,7 @@ perform file oldkey newbackend = do
ok <- getViaTmpUnchecked newkey $ \t -> do
-- Make a hard link to the old backend's
-- cached key, to avoid wasting disk space.
liftIO $ do
exists <- doesFileExist t
unless exists $ createLink src t
liftIO $ unlessM (doesFileExist t) $ createLink src t
return True
if ok
then do
@ -74,6 +72,4 @@ perform file oldkey newbackend = do
next $ Command.Add.cleanup file newkey
else stop
where
cleantmp t = do
exists <- doesFileExist t
when exists $ removeFile t
cleantmp t = whenM (doesFileExist t) $ removeFile t