implement Unavilable for borg bup ddar directory rsync
authorJoey Hess <joeyh@joeyh.name>
Wed, 16 Aug 2023 19:48:09 +0000 (15:48 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 16 Aug 2023 19:48:09 +0000 (15:48 -0400)
Only gcrypt remains to add support for. (Well, possibly also adb?)

Sponsored-by: Luke T. Shumaker on Patreon
CHANGELOG
Remote/Borg.hs
Remote/Bup.hs
Remote/Ddar.hs
Remote/Directory.hs
Remote/Helper/Git.hs
Remote/Helper/Path.hs [new file with mode: 0644]
Remote/Rsync.hs
git-annex.cabal

index 2ec2c1983c0b0fb890cf412097ca93b4a26e625b..5f5d3f034b9a1e4c6e17162d5852f4ddcc8d2f00 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,7 @@ git-annex (10.20230803) UNRELEASED; urgency=medium
   * Stop bundling curl in the OSX dmg and linux standalone image.
   * sync, assist, push, pull: Skip more types of remotes when they
     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.
   * Added AVAILABILITY UNAVAILABLE and the UNAVAILABLERESPONSE extension
     to the external special remote protocol.
index ba22c8cf59a506554dafadad0729e01cb3e31378..bdd9520603305fe56da7406bad6d57f542aecd95 100644 (file)
@@ -1,6 +1,6 @@
 {- 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.
  -}
@@ -23,6 +23,7 @@ import Annex.Tmp
 import Annex.SpecialRemote.Config
 import Remote.Helper.Special
 import Remote.Helper.ExportImport
+import Remote.Helper.Path
 import Annex.UUID
 import Types.ProposedAccepted
 import Utility.Metered
@@ -112,8 +113,7 @@ gen r u rc gc rs = do
                , gitconfig = gc
                , localpath = borgRepoLocalPath borgrepo
                , remotetype = remote
-               , availability = pure $
-                       if borgLocal borgrepo then LocallyAvailable else GloballyAvailable
+               , availability = checkAvailability borgrepo
                , readonly = False
                , appendonly = False
                -- When the user sets the appendonly field, they are
@@ -161,9 +161,13 @@ absBorgRepo r@(BorgRepo p)
 
 borgRepoLocalPath :: BorgRepo -> Maybe FilePath
 borgRepoLocalPath r@(BorgRepo p)
-       | borgLocal r && not (null p) = Just p
+       | borgLocal r = Just p
        | 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 u borgrepo c = prompt $ do
        imported <- getImported u
index c754850e22217f2f97f50e0b49152dc7a8122a72..8535edd02d83539b195678303532d502bf7ae4cc 100644 (file)
@@ -32,6 +32,7 @@ import qualified Remote.Helper.Ssh as Ssh
 import Annex.SpecialRemote.Config
 import Remote.Helper.Special
 import Remote.Helper.ExportImport
+import Remote.Helper.Path
 import Utility.Hash
 import Utility.UserInfo
 import Annex.UUID
@@ -97,8 +98,9 @@ gen r u rc gc rs = do
                        then Just buprepo
                        else Nothing
                , remotetype = remote
-               , availability = pure $
-                       if bupLocal buprepo then LocallyAvailable else GloballyAvailable
+               , availability = if null buprepo
+                       then pure LocallyAvailable
+                       else checkPathAvailability (bupLocal buprepo) buprepo
                , readonly = False
                , appendonly = False
                , untrustworthy = False
index 375920a325c50c2b6c8439bbdc140a469f335d54..9cc5f4a75ed494ffca38ffef9000d28f503bf44e 100644 (file)
@@ -25,6 +25,7 @@ import Config.Cost
 import Annex.SpecialRemote.Config
 import Remote.Helper.Special
 import Remote.Helper.ExportImport
+import Remote.Helper.Path
 import Annex.Ssh
 import Annex.UUID
 import Utility.SshHost
@@ -98,8 +99,9 @@ gen r u rc gc rs = do
                        then Just $ ddarRepoLocation ddarrepo
                        else Nothing
                , remotetype = remote
-               , availability = pure $
-                       if ddarLocal ddarrepo then LocallyAvailable else GloballyAvailable
+               , availability = checkPathAvailability
+                       (ddarLocal ddarrepo && not (null $ ddarRepoLocation ddarrepo))
+                       (ddarRepoLocation ddarrepo)
                , readonly = False
                , appendonly = False
                , untrustworthy = False
index b030bb2c464da6a64e4425f0a1363ed7d2b60ca7..afaf290306e25eb35e93d745e5040ef5d7f1ca8e 100644 (file)
@@ -34,6 +34,7 @@ import Config
 import Annex.SpecialRemote.Config
 import Remote.Helper.Special
 import Remote.Helper.ExportImport
+import Remote.Helper.Path
 import Types.Import
 import qualified Remote.Directory.LegacyChunked as Legacy
 import Annex.CopyFile
@@ -134,7 +135,7 @@ gen r u rc gc rs = do
                        , readonly = False
                        , appendonly = False
                        , untrustworthy = False
-                       , availability = pure LocallyAvailable
+                       , availability = checkPathAvailability True dir'
                        , remotetype = remote
                        , mkUnavailable = gen r u rc
                                (gc { remoteAnnexDirectory = Just "/dev/null" }) rs
index 70a111e27b77dd50cd43acb172af83c44870555f..8df181297fbd0f060e94af14ef170a058f939bba 100644 (file)
@@ -21,7 +21,7 @@ repoCheap = not . Git.repoIsUrl
 
 localpathCalc :: Git.Repo -> Maybe FilePath
 localpathCalc r
-       | availabilityCalc r == GloballyAvailable = Nothing
+       | not (Git.repoIsLocal r) && not (Git.repoIsLocalUnknown r) = Nothing
        | otherwise = Just $ fromRawFilePath $ Git.repoPath r
 
 availabilityCalc :: Git.Repo -> Availability
diff --git a/Remote/Helper/Path.hs b/Remote/Helper/Path.hs
new file mode 100644 (file)
index 0000000..fef6b48
--- /dev/null
@@ -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
+               )
index b0fceeab24a09dab5be63fc2d433b1b8be8f5a3d..aaf0848b868ecba966076ae3c7ab8fdd2c4e802e 100644 (file)
@@ -31,6 +31,7 @@ import Annex.Ssh
 import Annex.Perms
 import Remote.Helper.Special
 import Remote.Helper.ExportImport
+import Remote.Helper.Path
 import Types.Export
 import Types.ProposedAccepted
 import Remote.Rsync.RsyncUrl
@@ -120,8 +121,7 @@ gen r u rc gc rs = do
                        , readonly = False
                        , appendonly = False
                        , untrustworthy = False
-                       , availability = pure $
-                               if islocal then LocallyAvailable else GloballyAvailable
+                       , availability = checkPathAvailability islocal (rsyncUrl o)
                        , remotetype = remote
                        , mkUnavailable = return Nothing
                        , getInfo = return [("url", url)]
index 68c456a8491573dacffb2f498c0238974c195ad5..056503ca55d9aaa2ba5ea7595055f42d31566f65 100644 (file)
@@ -986,6 +986,7 @@ Executable git-annex
     Remote.Helper.Http
     Remote.Helper.Messages
     Remote.Helper.P2P
+    Remote.Helper.Path
     Remote.Helper.ReadOnly
     Remote.Helper.ThirdPartyPopulated
     Remote.Helper.Special