git-annex/Command/UnregisterUrl.hs
Joey Hess 98a3ba0ea5
restore old registerurl location tracking behavior
registerurl: When an url is claimed by a special remote other than the web,
update location tracking for that special remote.

registerurl's behavior was changed in commit
451171b7c1, apparently accidentially to not
update location tracking except for the web.

This makes registerurl followed by unregisterurl not be a no-op, when the
url happens to be claimed by a remote other than the web. It is a noop when
the url is unclaimed except by the web. I don't like the inconsistency,
and wish that registerurl and unregisterurl never updated location
tracking, which would be more in keeping with them being plumbing.

But there is the fact that it used to behave this way, and also it was
inconsistent that it updated location tracking for the web but not for
other remotes, unlike addurl. And there's an argument that the user might
not know what remote to expect to claim an url, so would be considerably in
the dark when using registerurl. (Although they have to know what content
gets downloaded, since they specify a key..)

Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
2023-04-05 17:06:44 -04:00

38 lines
1.3 KiB
Haskell

{- git-annex command
-
- Copyright 2015-2022 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE BangPatterns #-}
module Command.UnregisterUrl where
import Command
import Logs.Web
import Command.RegisterUrl (seekBatch, start, optParser, RegisterUrlOptions(..))
cmd :: Command
cmd = withAnnexOptions [jsonOptions] $ command "unregisterurl"
SectionPlumbing "unregisters an url for a key"
(paramPair paramKey paramUrl)
(seek <$$> optParser)
seek :: RegisterUrlOptions -> CommandSeek
seek o = case (batchOption o, keyUrlPairs o) of
(Batch fmt, _) -> seekBatch unregisterUrl o fmt
(NoBatch, ps) -> commandAction (start unregisterUrl o ps)
unregisterUrl :: Remote -> Key -> String -> Annex ()
unregisterUrl _remote key url = do
-- Remove the url no matter what downloader;
-- registerurl can set OtherDownloader, and this should also
-- be able to remove urls added by addurl, which may use
-- YoutubeDownloader.
forM_ [minBound..maxBound] $ \dl ->
setUrlMissing key (setDownloader url dl)
-- Unlike unregisterurl, this does not update location tracking
-- for remotes other than the web special remote. Doing so with
-- a remote that git-annex can drop content from would rather
-- unexpectedly leave content stranded on that remote.