2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010 Joey Hess <id@joeyh.name>
|
2010-11-02 23:04:24 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-11-02 23:04:24 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Drop where
|
|
|
|
|
|
|
|
import Command
|
2011-07-05 22:31:46 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Annex
|
2011-10-28 21:26:38 +00:00
|
|
|
import Annex.UUID
|
2011-10-15 20:21:08 +00:00
|
|
|
import Logs.Location
|
|
|
|
import Logs.Trust
|
2014-03-29 19:20:55 +00:00
|
|
|
import Logs.PreferredContent
|
2015-04-30 18:02:56 +00:00
|
|
|
import Annex.NumCopies
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2012-10-08 20:06:56 +00:00
|
|
|
import Annex.Wanted
|
2014-03-22 19:01:48 +00:00
|
|
|
import Annex.Notification
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2015-10-09 17:47:19 +00:00
|
|
|
import System.Log.Logger (debugM)
|
2014-03-29 19:20:55 +00:00
|
|
|
import qualified Data.Set as S
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2018-02-19 18:28:17 +00:00
|
|
|
cmd = withGlobalOptions [jobsOption, jsonOptions, annexedMatchingOptions] $
|
2015-07-10 17:18:46 +00:00
|
|
|
command "drop" SectionCommon
|
|
|
|
"remove content of files from repository"
|
|
|
|
paramPaths (seek <$$> optParser)
|
2015-07-08 21:59:06 +00:00
|
|
|
|
|
|
|
data DropOptions = DropOptions
|
|
|
|
{ dropFiles :: CmdParams
|
2015-07-09 19:23:14 +00:00
|
|
|
, dropFrom :: Maybe (DeferredParse Remote)
|
2015-07-08 21:59:06 +00:00
|
|
|
, autoMode :: Bool
|
2015-07-09 19:23:14 +00:00
|
|
|
, keyOptions :: Maybe KeyOptions
|
2016-07-06 15:54:46 +00:00
|
|
|
, batchOption :: BatchMode
|
2015-07-08 21:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser DropOptions
|
|
|
|
optParser desc = DropOptions
|
|
|
|
<$> cmdParams desc
|
2015-07-09 19:23:14 +00:00
|
|
|
<*> optional parseDropFromOption
|
2015-07-08 21:59:06 +00:00
|
|
|
<*> parseAutoOption
|
2016-08-03 16:37:12 +00:00
|
|
|
<*> optional parseKeyOptions
|
2016-07-06 15:54:46 +00:00
|
|
|
<*> parseBatchOption
|
2015-07-08 21:59:06 +00:00
|
|
|
|
2015-07-09 19:23:14 +00:00
|
|
|
parseDropFromOption :: Parser (DeferredParse Remote)
|
2017-05-31 20:20:55 +00:00
|
|
|
parseDropFromOption = parseRemoteOption <$> strOption
|
2015-07-09 14:41:17 +00:00
|
|
|
( long "from" <> short 'f' <> metavar paramRemote
|
|
|
|
<> help "drop content from a remote"
|
2015-09-14 17:19:04 +00:00
|
|
|
<> completeRemotes
|
2015-07-08 21:59:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
seek :: DropOptions -> CommandSeek
|
2019-06-19 16:35:08 +00:00
|
|
|
seek o = startConcurrency commandStages $
|
2016-07-06 15:54:46 +00:00
|
|
|
case batchOption o of
|
added -z
Added -z option to git-annex commands that use --batch, useful for
supporting filenames containing newlines.
It only controls input to --batch, the output will still be line delimited
unless --json or etc is used to get some other output. While git often
makes -z affect both input and output, I don't like trying them together,
and making it affect output would have been a significant complication,
and also git-annex output is generally not intended to be machine parsed,
unless using --json or a format option.
Commands that take pairs like "file key" still separate them with a space
in --batch mode. All such commands take care to support filenames with
spaces when parsing that, so there was no need to change it, and it would
have needed significant changes to the batch machinery to separate tose
with a null.
To make fromkey and registerurl support -z, I had to give them a --batch
option. The implicit batch mode they enter when not provided with input
parameters does not support -z as that would have complicated option
parsing. Seemed better to move these toward using the same --batch as
everything else, though the implicit batch mode can still be used.
This commit was sponsored by Ole-Morten Duesund on Patreon.
2018-09-20 20:09:21 +00:00
|
|
|
Batch fmt -> batchFilesMatching fmt go
|
2016-07-06 15:54:46 +00:00
|
|
|
NoBatch -> withKeyOptions (keyOptions o) (autoMode o)
|
2018-10-01 18:12:06 +00:00
|
|
|
(commandAction . startKeys o)
|
|
|
|
(withFilesInGit (commandAction . go))
|
2017-10-16 18:10:03 +00:00
|
|
|
=<< workTreeItems (dropFiles o)
|
2016-07-06 15:54:46 +00:00
|
|
|
where
|
|
|
|
go = whenAnnexed $ start o
|
2015-07-08 21:59:06 +00:00
|
|
|
|
|
|
|
start :: DropOptions -> FilePath -> Key -> CommandStart
|
2019-06-06 16:53:24 +00:00
|
|
|
start o file key = start' o key afile ai
|
2016-07-20 19:22:55 +00:00
|
|
|
where
|
2017-03-10 17:12:24 +00:00
|
|
|
afile = AssociatedFile (Just file)
|
2019-06-06 16:53:24 +00:00
|
|
|
ai = mkActionItem (key, afile)
|
2015-07-08 21:59:06 +00:00
|
|
|
|
2016-07-20 19:22:55 +00:00
|
|
|
start' :: DropOptions -> Key -> AssociatedFile -> ActionItem -> CommandStart
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
start' o key afile ai = do
|
2015-07-09 19:23:14 +00:00
|
|
|
from <- maybe (pure Nothing) (Just <$$> getParsed) (dropFrom o)
|
2015-07-08 21:59:06 +00:00
|
|
|
checkDropAuto (autoMode o) from afile key $ \numcopies ->
|
|
|
|
stopUnless (want from) $
|
|
|
|
case from of
|
2016-07-20 19:22:55 +00:00
|
|
|
Nothing -> startLocal afile ai numcopies key []
|
2015-07-08 21:59:06 +00:00
|
|
|
Just remote -> do
|
|
|
|
u <- getUUID
|
|
|
|
if Remote.uuid remote == u
|
2016-07-20 19:22:55 +00:00
|
|
|
then startLocal afile ai numcopies key []
|
|
|
|
else startRemote afile ai numcopies key remote
|
2015-07-08 21:59:06 +00:00
|
|
|
where
|
|
|
|
want from
|
|
|
|
| autoMode o = wantDrop False (Remote.uuid <$> from) (Just key) afile
|
|
|
|
| otherwise = return True
|
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
startKeys :: DropOptions -> (Key, ActionItem) -> CommandStart
|
|
|
|
startKeys o (key, ai) = start' o key (AssociatedFile Nothing) ai
|
2015-05-12 17:00:06 +00:00
|
|
|
|
2016-07-20 19:22:55 +00:00
|
|
|
startLocal :: AssociatedFile -> ActionItem -> NumCopies -> Key -> [VerifiedCopy] -> CommandStart
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
startLocal afile ai numcopies key preverified =
|
|
|
|
stopUnless (inAnnex key) $
|
finish CommandStart transition
The hoped for optimisation of CommandStart with -J did not materialize.
In fact, not runnign CommandStart in parallel is slower than -J3.
So, CommandStart are still run in parallel.
(The actual bad performance I've been seeing with -J in my big repo
has to do with building the remoteList.)
But, this is still progress toward making -J faster, because it gets rid
of the onlyActionOn roadblock in the way of making CommandCleanup jobs
run separate from CommandPerform jobs.
Added OnlyActionOn constructor for ActionItem which fixes the
onlyActionOn breakage in the last commit.
Made CustomOutput include an ActionItem, so even things using it can
specify OnlyActionOn.
In Command.Move and Command.Sync, there were CommandStarts that used
includeCommandAction, so output messages, which is no longer allowed.
Fixed by using startingCustomOutput, but that's still not quite right,
since it prevents message display for the includeCommandAction run
inside it too.
2019-06-12 13:23:26 +00:00
|
|
|
starting "drop" (OnlyActionOn key ai) $
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
performLocal key afile numcopies preverified
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2016-07-20 19:22:55 +00:00
|
|
|
startRemote :: AssociatedFile -> ActionItem -> NumCopies -> Key -> Remote -> CommandStart
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
startRemote afile ai numcopies key remote =
|
finish CommandStart transition
The hoped for optimisation of CommandStart with -J did not materialize.
In fact, not runnign CommandStart in parallel is slower than -J3.
So, CommandStart are still run in parallel.
(The actual bad performance I've been seeing with -J in my big repo
has to do with building the remoteList.)
But, this is still progress toward making -J faster, because it gets rid
of the onlyActionOn roadblock in the way of making CommandCleanup jobs
run separate from CommandPerform jobs.
Added OnlyActionOn constructor for ActionItem which fixes the
onlyActionOn breakage in the last commit.
Made CustomOutput include an ActionItem, so even things using it can
specify OnlyActionOn.
In Command.Move and Command.Sync, there were CommandStarts that used
includeCommandAction, so output messages, which is no longer allowed.
Fixed by using startingCustomOutput, but that's still not quite right,
since it prevents message display for the includeCommandAction run
inside it too.
2019-06-12 13:23:26 +00:00
|
|
|
starting ("drop " ++ Remote.name remote) (OnlyActionOn key ai) $
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
performRemote key afile numcopies remote
|
2011-10-28 21:26:38 +00:00
|
|
|
|
2015-10-08 20:55:11 +00:00
|
|
|
performLocal :: Key -> AssociatedFile -> NumCopies -> [VerifiedCopy] -> CommandPerform
|
2015-10-09 19:48:02 +00:00
|
|
|
performLocal key afile numcopies preverified = lockContentForRemoval key $ \contentlock -> do
|
2014-03-29 19:20:55 +00:00
|
|
|
u <- getUUID
|
2015-10-09 18:57:32 +00:00
|
|
|
(tocheck, verified) <- verifiableCopies key [u]
|
2015-10-09 19:48:02 +00:00
|
|
|
doDrop u (Just contentlock) key afile numcopies [] (preverified ++ verified) tocheck
|
2015-10-09 17:47:19 +00:00
|
|
|
( \proof -> do
|
|
|
|
liftIO $ debugM "drop" $ unwords
|
|
|
|
[ "Dropping from here"
|
2015-10-09 19:59:42 +00:00
|
|
|
, "proof:"
|
2015-10-09 17:47:19 +00:00
|
|
|
, show proof
|
|
|
|
]
|
2014-08-21 00:08:45 +00:00
|
|
|
removeAnnex contentlock
|
2014-03-22 19:01:48 +00:00
|
|
|
notifyDrop afile True
|
|
|
|
next $ cleanupLocal key
|
2015-10-09 15:09:46 +00:00
|
|
|
, do
|
2014-03-22 19:01:48 +00:00
|
|
|
notifyDrop afile False
|
|
|
|
stop
|
|
|
|
)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2014-03-29 19:20:55 +00:00
|
|
|
performRemote :: Key -> AssociatedFile -> NumCopies -> Remote -> CommandPerform
|
2014-08-21 00:08:45 +00:00
|
|
|
performRemote key afile numcopies remote = do
|
2011-10-28 21:26:38 +00:00
|
|
|
-- Filter the remote it's being dropped from out of the lists of
|
|
|
|
-- places assumed to have the key, and places to check.
|
2014-04-17 17:31:39 +00:00
|
|
|
-- When the local repo has the key, that's one additional copy,
|
2015-04-30 18:02:56 +00:00
|
|
|
-- as long as the local repo is not untrusted.
|
2015-10-09 18:57:32 +00:00
|
|
|
(tocheck, verified) <- verifiableCopies key [uuid]
|
2015-10-09 19:48:02 +00:00
|
|
|
doDrop uuid Nothing key afile numcopies [uuid] verified tocheck
|
2015-10-09 17:47:19 +00:00
|
|
|
( \proof -> do
|
|
|
|
liftIO $ debugM "drop" $ unwords
|
|
|
|
[ "Dropping from remote"
|
|
|
|
, show remote
|
2015-10-09 20:16:03 +00:00
|
|
|
, "proof:"
|
2015-10-09 17:47:19 +00:00
|
|
|
, show proof
|
|
|
|
]
|
2015-10-09 15:09:46 +00:00
|
|
|
ok <- Remote.removeKey remote key
|
|
|
|
next $ cleanupRemote key remote ok
|
|
|
|
, stop
|
|
|
|
)
|
2012-12-13 04:45:27 +00:00
|
|
|
where
|
2012-11-12 05:05:04 +00:00
|
|
|
uuid = Remote.uuid remote
|
2011-10-28 21:26:38 +00:00
|
|
|
|
|
|
|
cleanupLocal :: Key -> CommandCleanup
|
|
|
|
cleanupLocal key = do
|
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
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
cleanupRemote :: Key -> Remote -> Bool -> CommandCleanup
|
2011-11-09 20:54:18 +00:00
|
|
|
cleanupRemote key remote ok = do
|
bugfix: drop --from an unavailable remote no longer updates the location log, incorrectly, to say the remote does not have the key.
The comments correctly noted that the remote could drop the key and
yet False be returned due to some problem that occurred afterwards.
For example, if it's a network remote, it could drop the key just
as the network goes down, and so things timeout and a nonzero exit
from ssh is propigated through and False returned.
However... Most of the time, this scenario will not have happened.
False will mean the remote was not available or could not drop the key
at all.
So, instead of assuming the worst, just trust the status we have.
If we get it wrong, and the scenario above happened, our location
log will think the remote has the key. But the remote's location
log (assuming it has one) will know it dropped it, and the next sync
will regain consistency.
For a special remote, with no location log, our location log will be wrong,
but this is no different than the situation where someone else dropped
the key from the remote and we've not synced with them. The standard
paranoia about not trusting the location log to be the last word about
whether a remote has a key will save us from these situations. Ie,
if we try to drop the file, we'll actively check the remote,
and determine the inconsistency then.
2013-03-10 23:15:53 +00:00
|
|
|
when ok $
|
|
|
|
Remote.logStatus remote key InfoMissing
|
2011-10-28 21:26:38 +00:00
|
|
|
return ok
|
|
|
|
|
2015-10-09 15:09:46 +00:00
|
|
|
{- Before running the dropaction, checks specified remotes to
|
|
|
|
- verify that enough copies of a key exist to allow it to be
|
|
|
|
- safely removed (with no data loss).
|
2014-03-29 19:20:55 +00:00
|
|
|
-
|
|
|
|
- Also checks if it's required content, and refuses to drop if so.
|
|
|
|
-
|
|
|
|
- --force overrides and always allows dropping.
|
|
|
|
-}
|
2015-10-09 18:57:32 +00:00
|
|
|
doDrop
|
|
|
|
:: UUID
|
2015-10-09 19:48:02 +00:00
|
|
|
-> Maybe ContentRemovalLock
|
2015-10-09 18:57:32 +00:00
|
|
|
-> Key
|
|
|
|
-> AssociatedFile
|
|
|
|
-> NumCopies
|
|
|
|
-> [UUID]
|
|
|
|
-> [VerifiedCopy]
|
|
|
|
-> [UnVerifiedCopy]
|
|
|
|
-> (Maybe SafeDropProof -> CommandPerform, CommandPerform)
|
|
|
|
-> CommandPerform
|
2015-10-09 19:48:02 +00:00
|
|
|
doDrop dropfrom contentlock key afile numcopies skip preverified check (dropaction, nodropaction) =
|
2015-04-30 18:02:56 +00:00
|
|
|
ifM (Annex.getState Annex.force)
|
2015-10-09 17:47:19 +00:00
|
|
|
( dropaction Nothing
|
2015-10-09 15:09:46 +00:00
|
|
|
, ifM (checkRequiredContent dropfrom key afile)
|
2015-10-09 19:48:02 +00:00
|
|
|
( verifyEnoughCopiesToDrop nolocmsg key
|
|
|
|
contentlock numcopies
|
2015-10-09 17:47:19 +00:00
|
|
|
skip preverified check
|
|
|
|
(dropaction . Just)
|
|
|
|
(forcehint nodropaction)
|
2015-10-09 15:09:46 +00:00
|
|
|
, stop
|
|
|
|
)
|
2015-04-30 18:02:56 +00:00
|
|
|
)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2015-04-30 18:02:56 +00:00
|
|
|
nolocmsg = "Rather than dropping this file, try using: git annex move"
|
2015-10-09 15:09:46 +00:00
|
|
|
forcehint a = do
|
|
|
|
showLongNote "(Use --force to override this check, or adjust numcopies.)"
|
|
|
|
a
|
2013-04-01 19:20:42 +00:00
|
|
|
|
2014-03-29 19:20:55 +00:00
|
|
|
checkRequiredContent :: UUID -> Key -> AssociatedFile -> Annex Bool
|
|
|
|
checkRequiredContent u k afile =
|
|
|
|
ifM (isRequiredContent (Just u) S.empty (Just k) afile False)
|
|
|
|
( requiredContent
|
|
|
|
, return True
|
|
|
|
)
|
|
|
|
|
|
|
|
requiredContent :: Annex Bool
|
|
|
|
requiredContent = do
|
|
|
|
showLongNote "That file is required content, it cannot be dropped!"
|
|
|
|
showLongNote "(Use --force to override this check, or adjust required content configuration.)"
|
|
|
|
return False
|
|
|
|
|
2013-10-28 18:50:17 +00:00
|
|
|
{- In auto mode, only runs the action if there are enough
|
2014-01-21 21:08:49 +00:00
|
|
|
- copies on other semitrusted repositories. -}
|
2015-05-12 17:00:06 +00:00
|
|
|
checkDropAuto :: Bool -> Maybe Remote -> AssociatedFile -> Key -> (NumCopies -> CommandStart) -> CommandStart
|
2018-04-09 20:09:00 +00:00
|
|
|
checkDropAuto automode mremote afile key a =
|
|
|
|
go =<< getAssociatedFileNumCopies afile
|
2013-04-01 19:20:42 +00:00
|
|
|
where
|
2015-03-25 21:06:14 +00:00
|
|
|
go numcopies
|
2015-07-08 21:59:06 +00:00
|
|
|
| automode = do
|
2015-03-25 21:06:14 +00:00
|
|
|
locs <- Remote.keyLocations key
|
|
|
|
uuid <- getUUID
|
|
|
|
let remoteuuid = fromMaybe uuid $ Remote.uuid <$> mremote
|
|
|
|
locs' <- trustExclude UnTrusted $ filter (/= remoteuuid) locs
|
|
|
|
if NumCopies (length locs') >= numcopies
|
|
|
|
then a numcopies
|
|
|
|
else stop
|
|
|
|
| otherwise = a numcopies
|