let Remote.availability return Unavilable
This is groundwork for making special remotes like borg be skipped by sync when on an offline drive. Added AVAILABILITY UNAVAILABLE reponse and the UNAVAILABLERESPONSE extension to the external special remote protocol. The extension is needed because old git-annex, if it sees that response, will display a warning message. (It does continue as if the remote is globally available, which is acceptable, and the warning is only displayed at initremote due to remote.name.annex-availability caching, but still it seemed best to make this a protocol extension.) The remote.name.annex-availability git config is no longer used any more, and is documented as such. It was only used by external special remotes to cache the availability, to avoid needing to start the external process every time. Now that availability is queried as an Annex action, the external is only started by sync (and the assistant), when they actually check availability. Sponsored-by: Nicholas Golder-Manning on Patreon
This commit is contained in:
parent
7f7c95b771
commit
9286769d2c
28 changed files with 86 additions and 65 deletions
|
@ -113,7 +113,7 @@ gen r u rc gc rs = do
|
|||
, gitconfig = gc
|
||||
, localpath = Nothing
|
||||
, remotetype = remote
|
||||
, availability = LocallyAvailable
|
||||
, availability = pure LocallyAvailable
|
||||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
|
|
|
@ -88,7 +88,7 @@ gen r _ rc gc rs = do
|
|||
, readonly = True
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = return []
|
||||
|
|
|
@ -112,7 +112,8 @@ gen r u rc gc rs = do
|
|||
, gitconfig = gc
|
||||
, localpath = borgRepoLocalPath borgrepo
|
||||
, remotetype = remote
|
||||
, availability = if borgLocal borgrepo then LocallyAvailable else GloballyAvailable
|
||||
, availability = pure $
|
||||
if borgLocal borgrepo then LocallyAvailable else GloballyAvailable
|
||||
, readonly = False
|
||||
, appendonly = False
|
||||
-- When the user sets the appendonly field, they are
|
||||
|
|
|
@ -97,7 +97,8 @@ gen r u rc gc rs = do
|
|||
then Just buprepo
|
||||
else Nothing
|
||||
, remotetype = remote
|
||||
, availability = if bupLocal buprepo then LocallyAvailable else GloballyAvailable
|
||||
, availability = pure $
|
||||
if bupLocal buprepo then LocallyAvailable else GloballyAvailable
|
||||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
|
|
|
@ -98,7 +98,8 @@ gen r u rc gc rs = do
|
|||
then Just $ ddarRepoLocation ddarrepo
|
||||
else Nothing
|
||||
, remotetype = remote
|
||||
, availability = if ddarLocal ddarrepo then LocallyAvailable else GloballyAvailable
|
||||
, availability = pure $
|
||||
if ddarLocal ddarrepo then LocallyAvailable else GloballyAvailable
|
||||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
|
|
|
@ -134,7 +134,7 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = LocallyAvailable
|
||||
, availability = pure LocallyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = gen r u rc
|
||||
(gc { remoteAnnexDirectory = Just "/dev/null" }) rs
|
||||
|
|
|
@ -68,7 +68,7 @@ gen r u rc gc rs
|
|||
| externaltype == "readonly" = do
|
||||
c <- parsedRemoteConfig remote rc
|
||||
cst <- remoteCost gc c expensiveRemoteCost
|
||||
let rmt = mk c cst GloballyAvailable
|
||||
let rmt = mk c cst (pure GloballyAvailable)
|
||||
Nothing
|
||||
(externalInfo externaltype)
|
||||
Nothing
|
||||
|
@ -87,7 +87,6 @@ gen r u rc gc rs
|
|||
(Git.remoteName r) (Just rs)
|
||||
Annex.addCleanupAction (RemoteCleanup u) $ stopExternal external
|
||||
cst <- getCost external r gc c
|
||||
avail <- getAvailability external r gc
|
||||
exportsupported <- if exportTree c
|
||||
then checkExportSupported' external
|
||||
else return False
|
||||
|
@ -107,7 +106,7 @@ gen r u rc gc rs
|
|||
let cheapexportsupported = if exportsupported
|
||||
then exportIsSupported
|
||||
else exportUnsupported
|
||||
let rmt = mk c cst avail
|
||||
let rmt = mk c cst (getAvailability external)
|
||||
(Just (whereisKeyM external))
|
||||
(getInfoM external)
|
||||
(Just (claimUrlM external))
|
||||
|
@ -777,25 +776,16 @@ getCost external r gc pc =
|
|||
return c
|
||||
defcst = expensiveRemoteCost
|
||||
|
||||
{- Caches the availability in the git config to avoid needing to start up an
|
||||
- external special remote every time time just to ask it what its
|
||||
- availability is.
|
||||
-
|
||||
- Most remotes do not bother to implement a reply to this request;
|
||||
{- Most remotes do not bother to implement a reply to this request;
|
||||
- globally available is the default.
|
||||
-}
|
||||
getAvailability :: External -> Git.Repo -> RemoteGitConfig -> Annex Availability
|
||||
getAvailability external r gc =
|
||||
maybe (catchNonAsync query (const (pure defavail))) return
|
||||
(remoteAnnexAvailability gc)
|
||||
getAvailability :: External -> Annex Availability
|
||||
getAvailability external = catchNonAsync query (const (pure defavail))
|
||||
where
|
||||
query = do
|
||||
avail <- handleRequest external GETAVAILABILITY Nothing $ \req -> case req of
|
||||
AVAILABILITY avail -> result avail
|
||||
UNSUPPORTED_REQUEST -> result defavail
|
||||
_ -> Nothing
|
||||
setRemoteAvailability r avail
|
||||
return avail
|
||||
query = handleRequest external GETAVAILABILITY Nothing $ \req -> case req of
|
||||
AVAILABILITY avail -> result avail
|
||||
UNSUPPORTED_REQUEST -> result defavail
|
||||
_ -> Nothing
|
||||
defavail = GloballyAvailable
|
||||
|
||||
claimUrlM :: External -> URLString -> Annex Bool
|
||||
|
|
3
Remote/External/Types.hs
vendored
3
Remote/External/Types.hs
vendored
|
@ -110,6 +110,7 @@ supportedExtensionList :: ExtensionList
|
|||
supportedExtensionList = ExtensionList
|
||||
[ "INFO"
|
||||
, "GETGITREMOTENAME"
|
||||
, "UNAVAILABLERESPONSE"
|
||||
, asyncExtension
|
||||
]
|
||||
|
||||
|
@ -447,9 +448,11 @@ instance Proto.Serializable Size where
|
|||
instance Proto.Serializable Availability where
|
||||
serialize GloballyAvailable = "GLOBAL"
|
||||
serialize LocallyAvailable = "LOCAL"
|
||||
serialize Unavailable = "UNAVAILABLE"
|
||||
|
||||
deserialize "GLOBAL" = Just GloballyAvailable
|
||||
deserialize "LOCAL" = Just LocallyAvailable
|
||||
deserialize "UNAVAILABLE" = Just Unavailable
|
||||
deserialize _ = Nothing
|
||||
|
||||
instance Proto.Serializable [(URLString, Size, FilePath)] where
|
||||
|
|
|
@ -158,7 +158,7 @@ gen' r u c gc rs = do
|
|||
, readonly = Git.repoIsHttp r
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = availabilityCalc r
|
||||
, availability = pure (availabilityCalc r)
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = gitRepoInfo this
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{- Standard git remotes.
|
||||
-
|
||||
- Copyright 2011-2021 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2023 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -11,7 +11,6 @@
|
|||
module Remote.Git (
|
||||
remote,
|
||||
configRead,
|
||||
repoAvail,
|
||||
onLocalRepo,
|
||||
) where
|
||||
|
||||
|
@ -210,7 +209,7 @@ gen r u rc gc rs
|
|||
, readonly = Git.repoIsHttp r
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = availabilityCalc r
|
||||
, availability = repoAvail r
|
||||
, remotetype = remote
|
||||
, mkUnavailable = unavailable r u rc gc rs
|
||||
, getInfo = gitRepoInfo new
|
||||
|
@ -233,20 +232,24 @@ unavailable r = gen r'
|
|||
_ -> r -- already unavailable
|
||||
|
||||
{- Checks relatively inexpensively if a repository is available for use. -}
|
||||
repoAvail :: Git.Repo -> Annex Bool
|
||||
repoAvail :: Git.Repo -> Annex Availability
|
||||
repoAvail r
|
||||
| Git.repoIsHttp r = return True
|
||||
| Git.repoIsHttp r = return GloballyAvailable
|
||||
| Git.GCrypt.isEncrypted r = do
|
||||
g <- gitRepo
|
||||
liftIO $ do
|
||||
er <- Git.GCrypt.encryptedRemote g r
|
||||
if Git.repoIsLocal er || Git.repoIsLocalUnknown er
|
||||
then catchBoolIO $
|
||||
void (Git.Config.read er) >> return True
|
||||
else return True
|
||||
| Git.repoIsUrl r = return True
|
||||
| Git.repoIsLocalUnknown r = return False
|
||||
| otherwise = liftIO $ isJust <$> catchMaybeIO (Git.Config.read r)
|
||||
then checklocal er
|
||||
else return GloballyAvailable
|
||||
| Git.repoIsUrl r = return GloballyAvailable
|
||||
| Git.repoIsLocalUnknown r = return Unavailable
|
||||
| otherwise = checklocal r
|
||||
where
|
||||
checklocal r' = ifM (liftIO $ isJust <$> catchMaybeIO (Git.Config.read r'))
|
||||
( return LocallyAvailable
|
||||
, return Unavailable
|
||||
)
|
||||
|
||||
{- Tries to read the config for a specified remote, updates state, and
|
||||
- returns the updated repo. -}
|
||||
|
|
|
@ -130,7 +130,7 @@ gen r u rc gc rs = do
|
|||
, gitconfig = gc
|
||||
, localpath = Nothing
|
||||
, remotetype = remote
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, readonly = False
|
||||
-- content cannot be removed from a git-lfs repo
|
||||
, appendonly = True
|
||||
|
|
|
@ -103,7 +103,7 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = includeCredsInfo c (AWS.creds u) $
|
||||
|
|
|
@ -82,7 +82,7 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = gen r u rc
|
||||
(gc { remoteAnnexHookType = Just "!dne!" })
|
||||
|
|
|
@ -95,7 +95,7 @@ gen r u rc gc rs = do
|
|||
, readonly = True
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = return []
|
||||
|
|
|
@ -77,7 +77,7 @@ chainGen addr r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = gitRepoInfo this
|
||||
|
|
|
@ -120,7 +120,8 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = if islocal then LocallyAvailable else GloballyAvailable
|
||||
, availability = pure $
|
||||
if islocal then LocallyAvailable else GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = return [("url", url)]
|
||||
|
|
|
@ -249,7 +249,7 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = gen r u (M.insert hostField (Proposed "!dne!") rc) gc rs
|
||||
, getInfo = includeCredsInfo c (AWS.creds u) (s3Info c info)
|
||||
|
|
|
@ -108,7 +108,7 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = return []
|
||||
|
|
|
@ -93,7 +93,7 @@ gen r u rc gc rs = do
|
|||
, readonly = True
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = return []
|
||||
|
|
|
@ -117,7 +117,7 @@ gen r u rc gc rs = do
|
|||
, readonly = False
|
||||
, appendonly = False
|
||||
, untrustworthy = False
|
||||
, availability = GloballyAvailable
|
||||
, availability = pure GloballyAvailable
|
||||
, remotetype = remote
|
||||
, mkUnavailable = gen r u (M.insert urlField (Proposed "http://!dne!/") rc) gc rs
|
||||
, getInfo = includeCredsInfo c (davCreds u) $
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue