add reregisterurl command

What this can currently be used for is only to change an url from being
used by a special remote to being used by the web remote.

This could have been a --move-from option to registerurl. But, that would
have complicated its option and --batch processing, and also would have
complicated unregisterurl, which is implemented on top of
Command.Registerurl. So, a separate command was actually less complicated
to implement.

The generic description of the command is because I want to make this
command a catch-all for other url updating kind of things, if there are
ever any more. Also because it was hard to come up with a good name for the
specific action. I considered `git-annex moveurl`, but that seems to
indicate data is perhaps actually being moved, and seems to sit at the same
level as addurl and rmurl, and this command is at the plumbing
level of registerurl and unregisterurl.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2024-03-05 15:04:35 -04:00
parent 1bf02029f9
commit 016d1bee88
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 187 additions and 0 deletions

View file

@ -5,6 +5,8 @@ git-annex (10.20240228) UNRELEASED; urgency=medium
annexed files be verified with a checksum that is calculated
on a later download from the web. This will become the default later.
* Added dependency on unbounded-delays.
* reregisterurl: New command that can change an url from being
used by a special remote to being used by the web remote.
-- Joey Hess <id@joeyh.name> Tue, 27 Feb 2024 13:07:10 -0400

View file

@ -34,6 +34,7 @@ import qualified Command.MatchExpression
import qualified Command.FromKey
import qualified Command.RegisterUrl
import qualified Command.UnregisterUrl
import qualified Command.ReregisterUrl
import qualified Command.SetKey
import qualified Command.DropKey
import qualified Command.Transferrer
@ -196,6 +197,7 @@ cmds testoptparser testrunner mkbenchmarkgenerator = map addGitAnnexCommonOption
, Command.FromKey.cmd
, Command.RegisterUrl.cmd
, Command.UnregisterUrl.cmd
, Command.ReregisterUrl.cmd
, Command.SetKey.cmd
, Command.DropKey.cmd
, Command.Transferrer.cmd

79
Command/ReregisterUrl.hs Normal file
View file

@ -0,0 +1,79 @@
{- git-annex command
-
- Copyright 2015-2024 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Command.ReregisterUrl where
import Command
import Logs.Web
import Command.FromKey (keyOpt, keyOpt')
import qualified Remote
import Git.Types
cmd :: Command
cmd = withAnnexOptions [jsonOptions] $ command "reregisterurl"
SectionPlumbing "updates url registration information"
(paramKey)
(seek <$$> optParser)
data ReregisterUrlOptions = ReregisterUrlOptions
{ keyOpts :: CmdParams
, batchOption :: BatchMode
, moveFromOption :: Maybe (DeferredParse Remote)
}
optParser :: CmdParamsDesc -> Parser ReregisterUrlOptions
optParser desc = ReregisterUrlOptions
<$> cmdParams desc
<*> parseBatchOption False
<*> optional (mkParseRemoteOption <$> parseMoveFromOption)
parseMoveFromOption :: Parser RemoteName
parseMoveFromOption = strOption
( long "move-from" <> metavar paramRemote
<> completeRemotes
)
seek :: ReregisterUrlOptions -> CommandSeek
seek o = case (batchOption o, keyOpts o) of
(Batch fmt, _) -> seekBatch o fmt
(NoBatch, ps) -> commandAction (start o ps)
seekBatch :: ReregisterUrlOptions -> BatchFormat -> CommandSeek
seekBatch o fmt = batchOnly Nothing (keyOpts o) $
batchInput fmt (pure . parsebatch) $
batchCommandAction . start' o
where
parsebatch l = case keyOpt' l of
Left e -> Left e
Right k -> Right k
start :: ReregisterUrlOptions -> [String] -> CommandStart
start o (keyname:[]) = start' o (si, keyOpt keyname)
where
si = SeekInput [keyname]
start _ _ = giveup "specify a key"
start' :: ReregisterUrlOptions -> (SeekInput, Key) -> CommandStart
start' o (si, key) =
starting "reregisterurl" ai si $
perform o key
where
ai = ActionItemKey key
perform :: ReregisterUrlOptions -> Key -> CommandPerform
perform o key = maybe (pure Nothing) (Just <$$> getParsed) (moveFromOption o) >>= \case
Nothing -> next $ return True
Just r -> do
us <- map fst
. filter (\(_, d) -> d == OtherDownloader)
. map getDownloader
<$> getUrls key
us' <- filterM (\u -> (== r) <$> Remote.claimingUrl u) us
forM_ us' $ \u -> do
setUrlMissing key (setDownloader u OtherDownloader)
setUrlPresent key u
next $ return True

View file

@ -0,0 +1,29 @@
[[!comment format=mdwn
username="joey"
subject="""comment 6"""
date="2024-03-05T18:11:32Z"
content="""
Went far enough down implementing `registerurl --move-from` to be sure that
it would complicate the code far more than just adding a new `moveurl`
command. So despite it being a fairly unusual situation, a new command
is better than that option.
And implemented it:
joey@darkstar:~/tmp/x>git-annex registerurl WORM--bar http://example.com/bar.fooregisterurl http://example.com/bar.foo ok
joey@darkstar:~/tmp/x> git-annex whereis --key WORM--bar
whereis WORM--bar (1 copy)
dca0b5f9-659a-4928-84db-ff9fd74d8fc8 -- [foo]
foo: http://example.com/bar.foo
ok
joey@darkstar:~/tmp/x>git-annex reregisterurl WORM--bar --move-from=foo
reregisterurl WORM--bar ok
joey@darkstar:~/tmp/x>git-annex whereis --key WORM--bar
whereis WORM--bar (2 copies)
00000000-0000-0000-0000-000000000001 -- web
dca0b5f9-659a-4928-84db-ff9fd74d8fc8 -- [foo]
web: http://example.com/bar.foo
ok
"""]]

View file

@ -68,6 +68,8 @@ special remote that claims it. (Usually the web special remote.)
[[git-annex-unregisterurl]](1)
[[git-annex-reregisterurl]](1)
# AUTHOR
Joey Hess <id@joeyh.name>

View file

@ -0,0 +1,64 @@
# NAME
git-annex reregisterurl - updates url registration information
# SYNOPSIS
git annex reregisterurl `[key]`
# DESCRIPTION
This plumbing-level command updates information about the urls that are
registered for a key.
# OPTIONS
* `--move-from=name|uuid`
For each key, update any urls that are currently claimed by the
specified remote to be instead used by the web special remote.
This could be used eg, when a special remote was needed to provide
authorization to get an url, but the url has now become publically
available and so the web special remote can be used.
Note that, like `git-annex unregisterurl`, using this option unregisters
an url from a special remote, but it does not mark the content as not
present in that special remote. However, like `git-annex registerurl`,
this option does mark content as being present in the web special remote.
* `--batch`
In batch input mode, lines are read from stdin, and each line
should contain a key.
* `-z`
When in batch mode, the input is delimited by nulls instead of the usual
newlines.
* `--json`
Enable JSON output. This is intended to be parsed by programs that use
git-annex. Each line of output is a JSON object.
* `--json-error-messages`
Messages that would normally be output to standard error are included in
the JSON instead.
* Also the [[git-annex-common-options]](1) can be used.
# SEE ALSO
[[git-annex]](1)
[[git-annex-registerurl]](1)
[[git-annex-unregisterurl]](1)
# AUTHOR
Joey Hess <id@joeyh.name>
Warning: Automatically converted into a man page by mdwn2man. Edit with care.

View file

@ -57,6 +57,8 @@ for it, because the content may still be present on the remote.
[[git-annex-registerurl]](1)
[[git-annex-reregisterurl]](1)
[[git-annex-rmurl]](1)
# AUTHOR

View file

@ -677,6 +677,12 @@ content from the key-value store.
See [[git-annex-unregisterurl]](1) for details.
* `reregisterurl [key url]`
Updates url registration information.
See [[git-annex-reregisterurl]](1) for details.
* `setkey key file`
Moves a file into the annex as the content of a key.

View file

@ -685,6 +685,7 @@ Executable git-annex
Command.ReadPresentKey
Command.RecvKey
Command.RegisterUrl
Command.ReregisterUrl
Command.Reinit
Command.Reinject
Command.RemoteDaemon