2010-11-02 19:04:24 -04:00
|
|
|
{- 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
|
2011-01-16 16:05:05 -04:00
|
|
|
import Content
|
2010-11-08 15:15:21 -04:00
|
|
|
import Messages
|
2010-11-28 15:28:20 -04:00
|
|
|
import Utility
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2010-12-30 15:06:26 -04:00
|
|
|
command :: [Command]
|
2011-03-19 18:58:49 -04:00
|
|
|
command = [repoCommand "drop" paramPath seek
|
2010-12-30 15:06:26 -04:00
|
|
|
"indicate content of files not currently wanted"]
|
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
seek :: [CommandSeek]
|
2010-11-28 18:55:49 -04:00
|
|
|
seek = [withAttrFilesInGit "annex.numcopies" start]
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2010-11-02 19:04:24 -04:00
|
|
|
{- Indicates a file's content is not wanted anymore, and should be removed
|
|
|
|
- if it's safe to do so. -}
|
2010-12-30 14:19:16 -04:00
|
|
|
start :: CommandStartAttrFile
|
2010-11-28 15:28:20 -04:00
|
|
|
start (file, attr) = isAnnexed file $ \(key, backend) -> do
|
2010-11-02 19:04:24 -04:00
|
|
|
inbackend <- Backend.hasKey key
|
2011-05-15 02:02:46 -04:00
|
|
|
if inbackend
|
|
|
|
then do
|
2010-11-02 19:04:24 -04:00
|
|
|
showStart "drop" file
|
2011-05-15 02:02:46 -04:00
|
|
|
next $ perform key backend numcopies
|
|
|
|
else stop
|
2010-11-28 15:28:20 -04:00
|
|
|
where
|
|
|
|
numcopies = readMaybe attr :: Maybe Int
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2011-01-25 21:02:34 -04:00
|
|
|
perform :: Key -> Backend Annex -> Maybe Int -> CommandPerform
|
2010-11-28 15:28:20 -04:00
|
|
|
perform key backend numcopies = do
|
|
|
|
success <- Backend.removeKey backend key numcopies
|
2010-11-22 17:51:55 -04:00
|
|
|
if success
|
2011-05-15 02:02:46 -04:00
|
|
|
then next $ cleanup key
|
|
|
|
else stop
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
cleanup :: Key -> CommandCleanup
|
2010-11-02 19:04:24 -04:00
|
|
|
cleanup key = do
|
2011-05-17 03:10:13 -04:00
|
|
|
whenM (inAnnex key) $ removeAnnex key
|
2010-11-08 19:26:37 -04:00
|
|
|
logStatus key ValueMissing
|
|
|
|
return True
|