implement Unavilable for gcrypt

Sponsored-by: Brett Eisenberg on Patreon
This commit is contained in:
Joey Hess 2023-08-16 15:54:54 -04:00
parent 977403d338
commit 7aac60769a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 23 additions and 26 deletions

View file

@ -10,7 +10,7 @@ git-annex (10.20230803) UNRELEASED; urgency=medium
* Stop bundling curl in the OSX dmg and linux standalone image. * Stop bundling curl in the OSX dmg and linux standalone image.
* sync, assist, push, pull: Skip more types of remotes when they * sync, assist, push, pull: Skip more types of remotes when they
are not present due to eg being on a drive that is offline. are not present due to eg being on a drive that is offline.
(directory, borg, bup, ddar, rsync) (directory, borg, bup, ddar, gcrypt, rsync)
* info: Added available to the info displayed for a remote. * info: Added available to the info displayed for a remote.
* Added AVAILABILITY UNAVAILABLE and the UNAVAILABLERESPONSE extension * Added AVAILABILITY UNAVAILABLE and the UNAVAILABLERESPONSE extension
to the external special remote protocol. to the external special remote protocol.

View file

@ -158,7 +158,7 @@ gen' r u c gc rs = do
, readonly = Git.repoIsHttp r , readonly = Git.repoIsHttp r
, appendonly = False , appendonly = False
, untrustworthy = False , untrustworthy = False
, availability = pure (availabilityCalc r) , availability = repoAvail r
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = gitRepoInfo this , getInfo = gitRepoInfo this

View file

@ -231,26 +231,6 @@ unavailable r = gen r'
Nothing -> r { Git.location = Git.Unknown } Nothing -> r { Git.location = Git.Unknown }
_ -> r -- already unavailable _ -> r -- already unavailable
{- Checks relatively inexpensively if a repository is available for use. -}
repoAvail :: Git.Repo -> Annex Availability
repoAvail r
| 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 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 {- Tries to read the config for a specified remote, updates state, and
- returns the updated repo. -} - returns the updated repo. -}
tryGitConfigRead :: Bool -> Git.Repo -> Bool -> Annex Git.Repo tryGitConfigRead :: Bool -> Git.Repo -> Bool -> Annex Git.Repo

View file

@ -9,9 +9,11 @@ module Remote.Helper.Git where
import Annex.Common import Annex.Common
import qualified Git import qualified Git
import qualified Git.GCrypt
import Types.Availability import Types.Availability
import qualified Types.Remote as Remote import qualified Types.Remote as Remote
import qualified Utility.RawFilePath as R import qualified Utility.RawFilePath as R
import qualified Git.Config
import Data.Time.Clock.POSIX import Data.Time.Clock.POSIX
import System.PosixCompat.Files (modificationTime) import System.PosixCompat.Files (modificationTime)
@ -24,10 +26,25 @@ localpathCalc r
| not (Git.repoIsLocal r) && not (Git.repoIsLocalUnknown r) = Nothing | not (Git.repoIsLocal r) && not (Git.repoIsLocalUnknown r) = Nothing
| otherwise = Just $ fromRawFilePath $ Git.repoPath r | otherwise = Just $ fromRawFilePath $ Git.repoPath r
availabilityCalc :: Git.Repo -> Availability {- Checks relatively inexpensively if a repository is available for use. -}
availabilityCalc r repoAvail :: Git.Repo -> Annex Availability
| (Git.repoIsLocal r || Git.repoIsLocalUnknown r) = LocallyAvailable repoAvail r
| otherwise = GloballyAvailable | 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 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
)
{- Avoids performing an action on a local repository that's not usable. {- Avoids performing an action on a local repository that's not usable.
- Does not check that the repository is still available on disk. -} - Does not check that the repository is still available on disk. -}