2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Drop where
|
|
|
|
|
2010-11-08 23:26:37 +00:00
|
|
|
import Control.Monad (when)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Backend
|
|
|
|
import LocationLog
|
|
|
|
import Types
|
|
|
|
import Core
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2010-11-28 19:28:20 +00:00
|
|
|
import Utility
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
|
|
|
command = [Command "drop" paramPath seek
|
|
|
|
"indicate content of files not currently wanted"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-28 22:55:49 +00:00
|
|
|
seek = [withAttrFilesInGit "annex.numcopies" start]
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- Indicates a file's content is not wanted anymore, and should be removed
|
|
|
|
- if it's safe to do so. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartAttrFile
|
2010-11-28 19:28:20 +00:00
|
|
|
start (file, attr) = isAnnexed file $ \(key, backend) -> do
|
2010-11-02 23:04:24 +00:00
|
|
|
inbackend <- Backend.hasKey key
|
2010-11-22 21:51:55 +00:00
|
|
|
if not inbackend
|
2010-11-02 23:04:24 +00:00
|
|
|
then return Nothing
|
|
|
|
else do
|
|
|
|
showStart "drop" file
|
2010-11-28 19:28:20 +00:00
|
|
|
return $ Just $ perform key backend numcopies
|
|
|
|
where
|
|
|
|
numcopies = readMaybe attr :: Maybe Int
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: Key -> Backend -> Maybe Int -> CommandPerform
|
2010-11-28 19:28:20 +00:00
|
|
|
perform key backend numcopies = do
|
|
|
|
success <- Backend.removeKey backend key numcopies
|
2010-11-22 21:51:55 +00:00
|
|
|
if success
|
2010-11-02 23:04:24 +00:00
|
|
|
then return $ Just $ cleanup key
|
|
|
|
else return Nothing
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: Key -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup key = do
|
|
|
|
inannex <- inAnnex key
|
2010-11-22 21:51:55 +00:00
|
|
|
when inannex $ removeAnnex key
|
2010-11-08 23:26:37 +00:00
|
|
|
logStatus key ValueMissing
|
|
|
|
return True
|