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
|
|
|
|
|
|
|
|
import Command
|
2011-07-05 22:31:46 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Annex
|
2010-11-02 23:04:24 +00:00
|
|
|
import LocationLog
|
|
|
|
import Types
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2010-11-28 19:28:20 +00:00
|
|
|
import Utility
|
2011-07-05 22:31:46 +00:00
|
|
|
import Trust
|
|
|
|
import Config
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
2011-03-19 22:58:49 +00:00
|
|
|
command = [repoCommand "drop" paramPath seek
|
2010-12-30 19:06:26 +00:00
|
|
|
"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
|
2011-07-05 22:31:46 +00:00
|
|
|
start (file, attr) = isAnnexed file $ \(key, _) -> do
|
|
|
|
present <- inAnnex key
|
|
|
|
if present
|
2011-05-15 06:02:46 +00:00
|
|
|
then do
|
2010-11-02 23:04:24 +00:00
|
|
|
showStart "drop" file
|
2011-07-05 22:31:46 +00:00
|
|
|
next $ perform key numcopies
|
2011-05-15 06:02:46 +00:00
|
|
|
else stop
|
2010-11-28 19:28:20 +00:00
|
|
|
where
|
|
|
|
numcopies = readMaybe attr :: Maybe Int
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-07-05 22:31:46 +00:00
|
|
|
perform :: Key -> Maybe Int -> CommandPerform
|
|
|
|
perform key numcopies = do
|
|
|
|
success <- dropKey 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
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: Key -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup key = do
|
2011-05-17 07:10:13 +00:00
|
|
|
whenM (inAnnex key) $ removeAnnex key
|
2011-07-01 19:24:07 +00:00
|
|
|
logStatus key InfoMissing
|
2010-11-08 23:26:37 +00:00
|
|
|
return True
|
2011-07-05 22:31:46 +00:00
|
|
|
|
|
|
|
{- Checks remotes to verify that enough copies of a key exist to allow
|
|
|
|
- for a key to be safely removed (with no data loss), and fails with an
|
|
|
|
- error if not. -}
|
|
|
|
dropKey :: Key -> Maybe Int -> Annex Bool
|
|
|
|
dropKey key numcopiesM = do
|
|
|
|
force <- Annex.getState Annex.force
|
|
|
|
if force || numcopiesM == Just 0
|
|
|
|
then return True
|
|
|
|
else do
|
|
|
|
(remotes, trusteduuids) <- Remote.keyPossibilitiesTrusted key
|
|
|
|
untrusteduuids <- trustGet UnTrusted
|
|
|
|
let tocheck = Remote.remotesWithoutUUID remotes (trusteduuids++untrusteduuids)
|
|
|
|
numcopies <- getNumCopies numcopiesM
|
|
|
|
findcopies numcopies trusteduuids tocheck []
|
|
|
|
where
|
|
|
|
findcopies need have [] bad
|
|
|
|
| length have >= need = return True
|
|
|
|
| otherwise = notEnoughCopies need have bad
|
|
|
|
findcopies need have (r:rs) bad
|
|
|
|
| length have >= need = return True
|
|
|
|
| otherwise = do
|
|
|
|
let u = Remote.uuid r
|
|
|
|
let dup = u `elem` have
|
|
|
|
haskey <- Remote.hasKey r key
|
|
|
|
case (dup, haskey) of
|
|
|
|
(False, Right True) -> findcopies need (u:have) rs bad
|
|
|
|
(False, Left _) -> findcopies need have rs (r:bad)
|
|
|
|
_ -> findcopies need have rs bad
|
|
|
|
notEnoughCopies need have bad = do
|
|
|
|
unsafe
|
|
|
|
showLongNote $
|
|
|
|
"Could only verify the existence of " ++
|
|
|
|
show (length have) ++ " out of " ++ show need ++
|
|
|
|
" necessary copies"
|
|
|
|
Remote.showTriedRemotes bad
|
|
|
|
Remote.showLocations key have
|
|
|
|
hint
|
|
|
|
return False
|
|
|
|
unsafe = showNote "unsafe"
|
|
|
|
hint = showLongNote "(Use --force to override this check, or adjust annex.numcopies.)"
|