git-annex/Command/Drop.hs

50 lines
1.2 KiB
Haskell
Raw Normal View History

{- 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
2010-11-08 19:15:21 +00:00
import Messages
import Utility
command :: [Command]
command = [repoCommand "drop" paramPath seek
"indicate content of files not currently wanted"]
seek :: [CommandSeek]
2010-11-28 22:55:49 +00:00
seek = [withAttrFilesInGit "annex.numcopies" start]
2010-11-11 22:54:52 +00:00
{- 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
2011-05-15 06:02:46 +00:00
if inbackend
then do
showStart "drop" file
2011-05-15 06:02:46 +00:00
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
2010-11-22 21:51:55 +00:00
if success
2011-05-15 06:02:46 +00:00
then next $ cleanup key
else stop
cleanup :: Key -> CommandCleanup
cleanup key = do
whenM (inAnnex key) $ removeAnnex key
logStatus key ValueMissing
return True