convert checkAvailable to use availability rather than localpath

Every remote that sets localpath also implements an availability that
reutrns Unavailable when a local directory is not available.

This makes external remotes, and others that get support for
availability Unavailable to be used by checkAvailable. (Which is only
used by the assistant.)

Had to keep localpath though, since other parts of the assistant use it
to eg, sync with a remote when a removable drive is plugged in.

Sponsored-by: Jack Hill on Patreon
This commit is contained in:
Joey Hess 2023-08-16 15:57:30 -04:00
parent 7aac60769a
commit 83056e7b53
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 11 additions and 8 deletions

View file

@ -411,9 +411,12 @@ byCost = map snd . sortBy (comparing fst) . M.toList . costmap
costmap = M.fromListWith (++) . map costpair
costpair r = (cost r, [r])
checkAvailable :: Bool -> Remote -> IO Bool
checkAvailable assumenetworkavailable =
maybe (return assumenetworkavailable) doesDirectoryExist . localpath
checkAvailable :: Bool -> Remote -> Annex Bool
checkAvailable assumenetworkavailable r = tryNonAsync (availability r) >>= \case
Left _e -> return assumenetworkavailable
Right LocallyAvailable -> return True
Right GloballyAvailable -> return assumenetworkavailable
Right Unavailable -> return False
hasKey :: Remote -> Key -> Annex (Either String Bool)
hasKey r k = either (Left . show) Right <$> tryNonAsync (checkPresent r k)