reject batch options combined with non-batch options

Reject combinations of --batch (or --batch-keys) with options like --all or
--key or with filenames.

Most commands ignored the non-batch items when batch mode was enabled.

For some reason, addurl and dropkey both processed first the specified
non-batch items, followed by entering batch mode. Changed them to also
error out, for consistency.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2022-01-26 12:59:55 -04:00
parent 56a12eb84c
commit 835c50966a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
19 changed files with 50 additions and 27 deletions

View file

@ -26,6 +26,8 @@ git-annex (10.20220121) UNRELEASED; urgency=medium
* adb: Added ignorefinderror configuration parameter.
* Avoid crashing when run in a bare git repo that somehow contains an
index file.
* Reject combinations of --batch (or --batch-keys) with options like
--all or --key or with filenames.
-- Joey Hess <id@joeyh.name> Mon, 03 Jan 2022 14:01:14 -0400

View file

@ -77,8 +77,9 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
batchseeker (opts, NoBatch, params) =
mapM_ (\p -> go NoBatch opts (SeekInput [p], p)) params
batchseeker (opts, batchmode@(Batch fmt), _) =
batchInput fmt (pure . Right) (go batchmode opts)
batchseeker (opts, batchmode@(Batch fmt), params) =
batchOnly Nothing params $
batchInput fmt (pure . Right) (go batchmode opts)
go batchmode opts (si, p) =
unlessM (handler opts si p) $
@ -209,3 +210,8 @@ batchAnnexed fmt seeker keyaction = do
, providedMimeEncoding = Nothing
, providedLinkType = Nothing
}
batchOnly :: Maybe KeyOptions -> CmdParams -> Annex () -> Annex ()
batchOnly Nothing [] a = a
batchOnly _ _ _ = giveup "Cannot combine batch option with file or key options"

View file

@ -95,7 +95,8 @@ seek o = startConcurrency commandStages $ do
Batch fmt
| updateOnly o ->
giveup "--update --batch is not supported"
| otherwise -> batchFiles fmt gofile
| otherwise -> batchOnly Nothing (addThese o) $
batchFiles fmt gofile
NoBatch -> do
-- Avoid git ls-files complaining about files that
-- are not known to git yet, since this will add

View file

@ -119,10 +119,10 @@ seek o = startConcurrency commandStages $ do
then void $ commandAction $
startWeb addunlockedmatcher o' si u
else checkUrl addunlockedmatcher r o' si u
forM_ (addUrls o) (\u -> go (SeekInput [u], (o, u)))
case batchOption o of
Batch fmt -> batchInput fmt (pure . parseBatchInput o) go
NoBatch -> noop
Batch fmt -> batchOnly Nothing (addUrls o) $
batchInput fmt (pure . parseBatchInput o) go
NoBatch -> forM_ (addUrls o) (\u -> go (SeekInput [u], (o, u)))
parseBatchInput :: AddUrlOptions -> String -> Either String (AddUrlOptions, URLString)
parseBatchInput o s

View file

@ -51,7 +51,8 @@ seek o = startConcurrency commandStages $ do
(commandAction . keyaction)
(withFilesInGitAnnex ww seeker)
=<< workTreeItems ww (copyFiles o)
Batch fmt -> batchAnnexed fmt seeker keyaction
Batch fmt -> batchOnly (keyOptions o) (copyFiles o) $
batchAnnexed fmt seeker keyaction
where
ww = WarnUnmatchLsFiles

View file

@ -71,7 +71,8 @@ seek o = startConcurrency commandStages $ do
(commandAction . startKeys o from)
(withFilesInGitAnnex ww seeker)
=<< workTreeItems ww (dropFiles o)
Batch fmt -> batchAnnexed fmt seeker (startKeys o from)
Batch fmt -> batchOnly (keyOptions o) (dropFiles o) $
batchAnnexed fmt seeker (startKeys o from)
where
ww = WarnUnmatchLsFiles

View file

@ -33,11 +33,11 @@ seek :: DropKeyOptions -> CommandSeek
seek o = do
unlessM (Annex.getState Annex.force) $
giveup "dropkey can cause data loss; use --force if you're sure you want to do this"
withKeys (commandAction . start) (toDrop o)
case batchOption o of
Batch fmt -> batchInput fmt (pure . parsekey) $
batchCommandAction . start
NoBatch -> noop
NoBatch -> withKeys (commandAction . start) (toDrop o)
Batch fmt -> batchOnly Nothing (toDrop o) $
batchInput fmt (pure . parsekey) $
batchCommandAction . start
where
parsekey = maybe (Left "bad key") Right . deserializeKey

View file

@ -70,7 +70,8 @@ seek o = do
(commandAction . startKeys o)
(withFilesInGitAnnex ww seeker)
=<< workTreeItems ww (findThese o)
Batch fmt -> batchAnnexedFiles fmt seeker
Batch fmt -> batchOnly (keyOptions o) (findThese o) $
batchAnnexedFiles fmt seeker
where
ww = WarnUnmatchLsFiles

View file

@ -41,7 +41,8 @@ seek :: FromKeyOptions -> CommandSeek
seek o = do
matcher <- addUnlockedMatcher
case (batchOption o, keyFilePairs o) of
(Batch fmt, _) -> seekBatch matcher fmt
(Batch fmt, _) -> batchOnly Nothing (keyFilePairs o) $
seekBatch matcher fmt
-- older way of enabling batch input, does not support BatchNull
(NoBatch, []) -> seekBatch matcher (BatchFormat BatchLine (BatchKeys False))
(NoBatch, ps) -> do

View file

@ -49,7 +49,8 @@ seek o = startConcurrency downloadStages $ do
(commandAction . startKeys from)
(withFilesInGitAnnex ww seeker)
=<< workTreeItems ww (getFiles o)
Batch fmt -> batchAnnexed fmt seeker (startKeys from)
Batch fmt -> batchOnly (keyOptions o) (getFiles o) $
batchAnnexed fmt seeker (startKeys from)
where
ww = WarnUnmatchLsFiles

View file

@ -119,7 +119,8 @@ optParser desc = InfoOptions
seek :: InfoOptions -> CommandSeek
seek o = case batchOption o of
NoBatch -> withWords (commandAction . start o) (infoFor o)
Batch fmt -> batchInput fmt (pure . Right) (itemInfo o)
Batch fmt -> batchOnly Nothing (infoFor o) $
batchInput fmt (pure . Right) (itemInfo o)
start :: InfoOptions -> [String] -> CommandStart
start o [] = do

View file

@ -93,8 +93,9 @@ seek o = case batchOption o of
Batch fmt -> withMessageState $ \s -> case outputType s of
JSONOutput _ -> ifM limited
( giveup "combining --batch with file matching options is not currently supported"
, batchInput fmt parseJSONInput
(commandAction . batchCommandStart . startBatch)
, batchOnly (keyOptions o) (forFiles o) $
batchInput fmt parseJSONInput
(commandAction . batchCommandStart . startBatch)
)
_ -> giveup "--batch is currently only supported in --json mode"

View file

@ -64,7 +64,8 @@ seek o = startConcurrency stages $ do
(commandAction . keyaction)
(withFilesInGitAnnex ww seeker)
=<< workTreeItems ww (moveFiles o)
Batch fmt -> batchAnnexed fmt seeker keyaction
Batch fmt -> batchOnly (keyOptions o) (moveFiles o) $
batchAnnexed fmt seeker keyaction
where
seeker = AnnexedFileSeeker
{ startAction = start (fromToOptions o) (removeWhen o)

View file

@ -50,8 +50,9 @@ batchParser s = case separate (== ' ') (reverse s) of
seek :: ReKeyOptions -> CommandSeek
seek o = case batchOption o of
Batch fmt -> batchInput fmt batchParser
(batchCommandAction . uncurry start)
Batch fmt -> batchOnly Nothing (reKeyThese o) $
batchInput fmt batchParser
(batchCommandAction . uncurry start)
NoBatch -> withPairs
(\(si, p) -> commandAction (start si (parsekey p)))
(reKeyThese o)

View file

@ -32,7 +32,7 @@ optParser desc = RegisterUrlOptions
seek :: RegisterUrlOptions -> CommandSeek
seek o = case (batchOption o, keyUrlPairs o) of
(Batch (BatchFormat sep _), _) ->
(Batch (BatchFormat sep _), _) -> batchOnly Nothing (keyUrlPairs o) $
commandAction $ startMass setUrlPresent sep
-- older way of enabling batch input, does not support BatchNull
(NoBatch, []) -> commandAction $ startMass setUrlPresent BatchLine

View file

@ -29,7 +29,8 @@ optParser desc = RmUrlOptions
seek :: RmUrlOptions -> CommandSeek
seek o = case batchOption o of
Batch fmt -> batchInput fmt batchParser (batchCommandAction . start)
Batch fmt -> batchOnly Nothing (rmThese o) $
batchInput fmt batchParser (batchCommandAction . start)
NoBatch -> withPairs (commandAction . start) (rmThese o)
-- Split on the last space, since a FilePath can contain whitespace,

View file

@ -30,9 +30,10 @@ optParser desc = SetPresentKeyOptions
seek :: SetPresentKeyOptions -> CommandSeek
seek o = case batchOption o of
Batch fmt -> batchInput fmt
(pure . parseKeyStatus . words)
(batchCommandAction . uncurry start)
Batch fmt -> batchOnly Nothing (params o) $
batchInput fmt
(pure . parseKeyStatus . words)
(batchCommandAction . uncurry start)
NoBatch -> either giveup (commandAction . start (SeekInput (params o)))
(parseKeyStatus $ params o)

View file

@ -62,7 +62,8 @@ seek o = do
(commandAction . startKeys o m)
(withFilesInGitAnnex ww seeker)
=<< workTreeItems ww (whereisFiles o)
Batch fmt -> batchAnnexed fmt seeker (startKeys o m)
Batch fmt -> batchOnly (keyOptions o) (whereisFiles o) $
batchAnnexed fmt seeker (startKeys o m)
where
ww = WarnUnmatchLsFiles

View file

@ -21,3 +21,5 @@ MD5E-s5663237--4608ffbd6b78ce3a325eb338fa556589.nii.gz
### What version of git-annex are you using? On what operating system?
`8.20211231+git140-gc3817495f-1~ndall+1`
> [[fixed|done]] --[[Joey]]