implement Unavilable for borg bup ddar directory rsync

Only gcrypt remains to add support for. (Well, possibly also adb?)

Sponsored-by: Luke T. Shumaker on Patreon
This commit is contained in:
Joey Hess 2023-08-16 15:48:09 -04:00
parent 67c99a4db7
commit 977403d338
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 42 additions and 12 deletions

View file

@ -10,6 +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)
* 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

@ -1,6 +1,6 @@
{- Using borg as a remote. {- Using borg as a remote.
- -
- Copyright 2020,2021 Joey Hess <id@joeyh.name> - Copyright 2020,2023 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -23,6 +23,7 @@ import Annex.Tmp
import Annex.SpecialRemote.Config import Annex.SpecialRemote.Config
import Remote.Helper.Special import Remote.Helper.Special
import Remote.Helper.ExportImport import Remote.Helper.ExportImport
import Remote.Helper.Path
import Annex.UUID import Annex.UUID
import Types.ProposedAccepted import Types.ProposedAccepted
import Utility.Metered import Utility.Metered
@ -112,8 +113,7 @@ gen r u rc gc rs = do
, gitconfig = gc , gitconfig = gc
, localpath = borgRepoLocalPath borgrepo , localpath = borgRepoLocalPath borgrepo
, remotetype = remote , remotetype = remote
, availability = pure $ , availability = checkAvailability borgrepo
if borgLocal borgrepo then LocallyAvailable else GloballyAvailable
, readonly = False , readonly = False
, appendonly = False , appendonly = False
-- When the user sets the appendonly field, they are -- When the user sets the appendonly field, they are
@ -161,9 +161,13 @@ absBorgRepo r@(BorgRepo p)
borgRepoLocalPath :: BorgRepo -> Maybe FilePath borgRepoLocalPath :: BorgRepo -> Maybe FilePath
borgRepoLocalPath r@(BorgRepo p) borgRepoLocalPath r@(BorgRepo p)
| borgLocal r && not (null p) = Just p | borgLocal r = Just p
| otherwise = Nothing | otherwise = Nothing
checkAvailability :: BorgRepo -> Annex Availability
checkAvailability borgrepo@(BorgRepo r) =
checkPathAvailability (borgLocal borgrepo) r
listImportableContentsM :: UUID -> BorgRepo -> ParsedRemoteConfig -> Annex (Maybe (ImportableContentsChunkable Annex (ContentIdentifier, ByteSize))) listImportableContentsM :: UUID -> BorgRepo -> ParsedRemoteConfig -> Annex (Maybe (ImportableContentsChunkable Annex (ContentIdentifier, ByteSize)))
listImportableContentsM u borgrepo c = prompt $ do listImportableContentsM u borgrepo c = prompt $ do
imported <- getImported u imported <- getImported u

View file

@ -32,6 +32,7 @@ import qualified Remote.Helper.Ssh as Ssh
import Annex.SpecialRemote.Config import Annex.SpecialRemote.Config
import Remote.Helper.Special import Remote.Helper.Special
import Remote.Helper.ExportImport import Remote.Helper.ExportImport
import Remote.Helper.Path
import Utility.Hash import Utility.Hash
import Utility.UserInfo import Utility.UserInfo
import Annex.UUID import Annex.UUID
@ -97,8 +98,9 @@ gen r u rc gc rs = do
then Just buprepo then Just buprepo
else Nothing else Nothing
, remotetype = remote , remotetype = remote
, availability = pure $ , availability = if null buprepo
if bupLocal buprepo then LocallyAvailable else GloballyAvailable then pure LocallyAvailable
else checkPathAvailability (bupLocal buprepo) buprepo
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False , untrustworthy = False

View file

@ -25,6 +25,7 @@ import Config.Cost
import Annex.SpecialRemote.Config import Annex.SpecialRemote.Config
import Remote.Helper.Special import Remote.Helper.Special
import Remote.Helper.ExportImport import Remote.Helper.ExportImport
import Remote.Helper.Path
import Annex.Ssh import Annex.Ssh
import Annex.UUID import Annex.UUID
import Utility.SshHost import Utility.SshHost
@ -98,8 +99,9 @@ gen r u rc gc rs = do
then Just $ ddarRepoLocation ddarrepo then Just $ ddarRepoLocation ddarrepo
else Nothing else Nothing
, remotetype = remote , remotetype = remote
, availability = pure $ , availability = checkPathAvailability
if ddarLocal ddarrepo then LocallyAvailable else GloballyAvailable (ddarLocal ddarrepo && not (null $ ddarRepoLocation ddarrepo))
(ddarRepoLocation ddarrepo)
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False , untrustworthy = False

View file

@ -34,6 +34,7 @@ import Config
import Annex.SpecialRemote.Config import Annex.SpecialRemote.Config
import Remote.Helper.Special import Remote.Helper.Special
import Remote.Helper.ExportImport import Remote.Helper.ExportImport
import Remote.Helper.Path
import Types.Import import Types.Import
import qualified Remote.Directory.LegacyChunked as Legacy import qualified Remote.Directory.LegacyChunked as Legacy
import Annex.CopyFile import Annex.CopyFile
@ -134,7 +135,7 @@ gen r u rc gc rs = do
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False , untrustworthy = False
, availability = pure LocallyAvailable , availability = checkPathAvailability True dir'
, remotetype = remote , remotetype = remote
, mkUnavailable = gen r u rc , mkUnavailable = gen r u rc
(gc { remoteAnnexDirectory = Just "/dev/null" }) rs (gc { remoteAnnexDirectory = Just "/dev/null" }) rs

View file

@ -21,7 +21,7 @@ repoCheap = not . Git.repoIsUrl
localpathCalc :: Git.Repo -> Maybe FilePath localpathCalc :: Git.Repo -> Maybe FilePath
localpathCalc r localpathCalc r
| availabilityCalc r == GloballyAvailable = 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 availabilityCalc :: Git.Repo -> Availability

19
Remote/Helper/Path.hs Normal file
View file

@ -0,0 +1,19 @@
{- Utilities for remotes located in a path in the filesystem.
-
- Copyright 2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Remote.Helper.Path where
import Annex.Common
import Types.Availability
checkPathAvailability :: Bool -> FilePath -> Annex Availability
checkPathAvailability islocal d
| not islocal = return GloballyAvailable
| otherwise = ifM (liftIO $ doesDirectoryExist d)
( return LocallyAvailable
, return Unavailable
)

View file

@ -31,6 +31,7 @@ import Annex.Ssh
import Annex.Perms import Annex.Perms
import Remote.Helper.Special import Remote.Helper.Special
import Remote.Helper.ExportImport import Remote.Helper.ExportImport
import Remote.Helper.Path
import Types.Export import Types.Export
import Types.ProposedAccepted import Types.ProposedAccepted
import Remote.Rsync.RsyncUrl import Remote.Rsync.RsyncUrl
@ -120,8 +121,7 @@ gen r u rc gc rs = do
, readonly = False , readonly = False
, appendonly = False , appendonly = False
, untrustworthy = False , untrustworthy = False
, availability = pure $ , availability = checkPathAvailability islocal (rsyncUrl o)
if islocal then LocallyAvailable else GloballyAvailable
, remotetype = remote , remotetype = remote
, mkUnavailable = return Nothing , mkUnavailable = return Nothing
, getInfo = return [("url", url)] , getInfo = return [("url", url)]

View file

@ -986,6 +986,7 @@ Executable git-annex
Remote.Helper.Http Remote.Helper.Http
Remote.Helper.Messages Remote.Helper.Messages
Remote.Helper.P2P Remote.Helper.P2P
Remote.Helper.Path
Remote.Helper.ReadOnly Remote.Helper.ReadOnly
Remote.Helper.ThirdPartyPopulated Remote.Helper.ThirdPartyPopulated
Remote.Helper.Special Remote.Helper.Special