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
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
, Command.FromKey.cmd
, Command.RegisterUrl.cmd
, Command.UnregisterUrl.cmd
+ , Command.ReregisterUrl.cmd
, Command.SetKey.cmd
, Command.DropKey.cmd
, Command.Transferrer.cmd
--- /dev/null
+{- 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
--- /dev/null
+[[!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
+"""]]
[[git-annex-unregisterurl]](1)
+[[git-annex-reregisterurl]](1)
+
# AUTHOR
Joey Hess <id@joeyh.name>
--- /dev/null
+# 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.
[[git-annex-registerurl]](1)
+[[git-annex-reregisterurl]](1)
+
[[git-annex-rmurl]](1)
# AUTHOR
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.
Command.ReadPresentKey
Command.RecvKey
Command.RegisterUrl
+ Command.ReregisterUrl
Command.Reinit
Command.Reinject
Command.RemoteDaemon