git-annex/Command/Drop.hs
Joey Hess c91929f693 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.
2011-05-17 03:13:11 -04:00

49 lines
1.2 KiB
Haskell

{- git-annex command
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Drop where
import Command
import qualified Backend
import LocationLog
import Types
import Content
import Messages
import Utility
command :: [Command]
command = [repoCommand "drop" paramPath seek
"indicate content of files not currently wanted"]
seek :: [CommandSeek]
seek = [withAttrFilesInGit "annex.numcopies" start]
{- Indicates a file's content is not wanted anymore, and should be removed
- if it's safe to do so. -}
start :: CommandStartAttrFile
start (file, attr) = isAnnexed file $ \(key, backend) -> do
inbackend <- Backend.hasKey key
if inbackend
then do
showStart "drop" file
next $ perform key backend numcopies
else stop
where
numcopies = readMaybe attr :: Maybe Int
perform :: Key -> Backend Annex -> Maybe Int -> CommandPerform
perform key backend numcopies = do
success <- Backend.removeKey backend key numcopies
if success
then next $ cleanup key
else stop
cleanup :: Key -> CommandCleanup
cleanup key = do
whenM (inAnnex key) $ removeAnnex key
logStatus key ValueMissing
return True