move untrust forcing from Logs.Trust into Remote

No behavior changes here, but this is groundwork for letting remotes
such as borg vary untrust forcing depending on configuration.
This commit is contained in:
Joey Hess 2020-12-28 15:08:53 -04:00
parent 5ce7fce74a
commit 36133f27c0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
22 changed files with 42 additions and 13 deletions

View file

@ -64,22 +64,15 @@ trustMap = maybe trustMapLoad return =<< Annex.getState Annex.trustmap
{- Loads the map, updating the cache, -} {- Loads the map, updating the cache, -}
trustMapLoad :: Annex TrustMap trustMapLoad :: Annex TrustMap
trustMapLoad = do trustMapLoad = do
overrides <- Annex.getState Annex.forcetrust forceoverrides <- Annex.getState Annex.forcetrust
l <- remoteList l <- remoteList
-- Export/import remotes are normally untrusted, because they are let untrustoverrides = M.fromList $
-- not key/value stores and there are many ways that content stored map (\r -> (Types.Remote.uuid r, UnTrusted))
-- on them can be lost. An exception is ones with versionedExport set. (filter Types.Remote.untrustworthy l)
let isexportimport r = Types.Remote.isExportSupported r
<||> Types.Remote.isImportSupported r
let isuntrustworthy r = isexportimport r
<&&> pure (not (Types.Remote.versionedExport (Types.Remote.exportActions r)))
untrustworthy <- filterM isuntrustworthy l
let trustoverrides = M.fromList $
map (\r -> (Types.Remote.uuid r, UnTrusted)) untrustworthy
logged <- trustMapRaw logged <- trustMapRaw
let configured = M.fromList $ mapMaybe configuredtrust l let configured = M.fromList $ mapMaybe configuredtrust l
let m = M.unionWith min trustoverrides $ let m = M.unionWith min untrustoverrides $
M.union overrides $ M.union forceoverrides $
M.union configured logged M.union configured logged
Annex.changeState $ \s -> s { Annex.trustmap = Just m } Annex.changeState $ \s -> s { Annex.trustmap = Just m }
return m return m

View file

@ -101,6 +101,7 @@ gen r u rc gc rs = do
, availability = LocallyAvailable , availability = LocallyAvailable
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = return , getInfo = return
[ ("androidserial", fromAndroidSerial serial) [ ("androidserial", fromAndroidSerial serial)

View file

@ -86,6 +86,7 @@ gen r _ rc gc rs = do
, getRepo = return r , getRepo = return r
, readonly = True , readonly = True
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -108,6 +108,7 @@ gen r u rc gc rs = do
, availability = if borgLocal borgrepo then LocallyAvailable else GloballyAvailable , availability = if borgLocal borgrepo then LocallyAvailable else GloballyAvailable
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = True
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = return [("repo", borgrepo)] , getInfo = return [("repo", borgrepo)]
, claimUrl = Nothing , claimUrl = Nothing

View file

@ -95,6 +95,7 @@ gen r u rc gc rs = do
, availability = if bupLocal buprepo then LocallyAvailable else GloballyAvailable , availability = if bupLocal buprepo then LocallyAvailable else GloballyAvailable
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = return [("repo", buprepo)] , getInfo = return [("repo", buprepo)]
, claimUrl = Nothing , claimUrl = Nothing

View file

@ -98,6 +98,7 @@ gen r u rc gc rs = do
, availability = if ddarLocal ddarrepo then LocallyAvailable else GloballyAvailable , availability = if ddarLocal ddarrepo then LocallyAvailable else GloballyAvailable
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = return [("repo", ddarRepoLocation ddarrepo)] , getInfo = return [("repo", ddarRepoLocation ddarrepo)]
, claimUrl = Nothing , claimUrl = Nothing

View file

@ -115,6 +115,7 @@ gen r u rc gc rs = do
, localpath = Just dir' , localpath = Just dir'
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = LocallyAvailable , availability = LocallyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = gen r u rc , mkUnavailable = gen r u rc

View file

@ -144,6 +144,7 @@ gen r u rc gc rs
, gitconfig = gc , gitconfig = gc
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = avail , availability = avail
, remotetype = remote , remotetype = remote
{ exportSupported = cheapexportsupported } { exportSupported = cheapexportsupported }

View file

@ -153,6 +153,7 @@ gen' r u c gc rs = do
, gitconfig = gc , gitconfig = gc
, readonly = Git.repoIsHttp r , readonly = Git.repoIsHttp r
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = availabilityCalc r , availability = availabilityCalc r
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -205,6 +205,7 @@ gen r u rc gc rs
, gitconfig = gc , gitconfig = gc
, readonly = Git.repoIsHttp r , readonly = Git.repoIsHttp r
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = availabilityCalc r , availability = availabilityCalc r
, remotetype = remote , remotetype = remote
, mkUnavailable = unavailable r u rc gc rs , mkUnavailable = unavailable r u rc gc rs

View file

@ -133,6 +133,7 @@ gen r u rc gc rs = do
, readonly = False , readonly = False
-- content cannot be removed from a git-lfs repo -- content cannot be removed from a git-lfs repo
, appendonly = True , appendonly = True
, untrustworthy = False
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = gitRepoInfo (this c cst h) , getInfo = gitRepoInfo (this c cst h)
, claimUrl = Nothing , claimUrl = Nothing

View file

@ -99,6 +99,7 @@ gen r u rc gc rs = new
, localpath = Nothing , localpath = Nothing
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -204,6 +204,16 @@ adjustExportImport' isexport isimport r rs = do
-- in confusing ways when there's an export -- in confusing ways when there's an export
-- conflict (or an import conflict). -- conflict (or an import conflict).
, checkPresentCheap = False , checkPresentCheap = False
-- Export/import remotes can lose content stored on them in
-- many ways. This is not a problem with versioned
-- ones though, since they still allow accessing by Key.
-- And for thirdPartyPopulated, it depends on how the
-- content gets actually stored in the remote, so
-- is not overriddden here.
, untrustworthy =
if versioned || thirdPartyPopulated (remotetype r)
then untrustworthy r
else False
-- git-annex testremote cannot be used to test -- git-annex testremote cannot be used to test
-- import/export since it stores keys. -- import/export since it stores keys.
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -80,6 +80,7 @@ gen r u rc gc rs = do
, gitconfig = gc , gitconfig = gc
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = gen r u rc , mkUnavailable = gen r u rc

View file

@ -88,6 +88,7 @@ gen r u rc gc rs = do
, getRepo = return r , getRepo = return r
, readonly = True , readonly = True
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -74,6 +74,7 @@ chainGen addr r u rc gc rs = do
, gitconfig = gc , gitconfig = gc
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -118,6 +118,7 @@ gen r u rc gc rs = do
else Nothing else Nothing
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = if islocal then LocallyAvailable else GloballyAvailable , availability = if islocal then LocallyAvailable else GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -234,6 +234,7 @@ gen r u rc gc rs = do
, localpath = Nothing , localpath = Nothing
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = gen r u (M.insert hostField (Proposed "!dne!") rc) gc rs , mkUnavailable = gen r u (M.insert hostField (Proposed "!dne!") rc) gc rs

View file

@ -107,6 +107,7 @@ gen r u rc gc rs = do
, localpath = Nothing , localpath = Nothing
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -72,6 +72,7 @@ gen r _ rc gc rs = do
, getRepo = return r , getRepo = return r
, readonly = True , readonly = True
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing

View file

@ -115,6 +115,7 @@ gen r u rc gc rs = do
, localpath = Nothing , localpath = Nothing
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False
, availability = GloballyAvailable , availability = GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = gen r u (M.insert urlField (Proposed "http://!dne!/") rc) gc rs , mkUnavailable = gen r u (M.insert urlField (Proposed "http://!dne!/") rc) gc rs

View file

@ -143,6 +143,13 @@ data RemoteA a = Remote
-- a Remote can allow writes but not have a way to delete content -- a Remote can allow writes but not have a way to delete content
-- from it. -- from it.
, appendonly :: Bool , appendonly :: Bool
-- Set if a remote cannot be trusted to continue to contain the
-- contents of files stored there. Notably, most export/import
-- remotes are untrustworthy because they are not key/value stores.
-- Since this prevents the user from adjusting a remote's trust
-- level, it's often better not not set it and instead let the user
-- decide.
, untrustworthy :: Bool
-- a Remote can be globally available. (Ie, "in the cloud".) -- a Remote can be globally available. (Ie, "in the cloud".)
, availability :: Availability , availability :: Availability
-- the type of the remote -- the type of the remote