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:
parent
7aac60769a
commit
83056e7b53
5 changed files with 11 additions and 8 deletions
|
@ -59,11 +59,11 @@ import Control.Concurrent.Async
|
||||||
reconnectRemotes :: [Remote] -> Assistant ()
|
reconnectRemotes :: [Remote] -> Assistant ()
|
||||||
reconnectRemotes [] = recordExportCommit
|
reconnectRemotes [] = recordExportCommit
|
||||||
reconnectRemotes rs = void $ do
|
reconnectRemotes rs = void $ do
|
||||||
rs' <- liftIO $ filterM (Remote.checkAvailable True) rs
|
rs' <- liftAnnex $ filterM (Remote.checkAvailable True) rs
|
||||||
unless (null rs') $ do
|
unless (null rs') $ do
|
||||||
failedrs <- syncAction rs' (const go)
|
failedrs <- syncAction rs' (const go)
|
||||||
forM_ failedrs $ \r ->
|
forM_ failedrs $ \r ->
|
||||||
whenM (liftIO $ Remote.checkAvailable False r) $
|
whenM (liftAnnex $ Remote.checkAvailable False r) $
|
||||||
repoHasProblem (Remote.uuid r) (syncRemote r)
|
repoHasProblem (Remote.uuid r) (syncRemote r)
|
||||||
mapM_ signal $ filter (`notElem` failedrs) rs'
|
mapM_ signal $ filter (`notElem` failedrs) rs'
|
||||||
recordExportCommit
|
recordExportCommit
|
||||||
|
|
|
@ -51,7 +51,7 @@ exportThread = namedThread "Exporter" $ runEvery (Seconds 30) <~> do
|
||||||
- to avoid ugly messages when a removable drive is not attached.
|
- to avoid ugly messages when a removable drive is not attached.
|
||||||
-}
|
-}
|
||||||
exportTargets :: Assistant [Remote]
|
exportTargets :: Assistant [Remote]
|
||||||
exportTargets = liftIO . filterM (Remote.checkAvailable True)
|
exportTargets = liftAnnex . filterM (Remote.checkAvailable True)
|
||||||
=<< candidates <$> getDaemonStatus
|
=<< candidates <$> getDaemonStatus
|
||||||
where
|
where
|
||||||
candidates = filter (not . Remote.readonly) . exportRemotes
|
candidates = filter (not . Remote.readonly) . exportRemotes
|
||||||
|
|
|
@ -56,7 +56,7 @@ handleRemoteProblem urlrenderer rmt = do
|
||||||
handleRemoteProblem' :: Git.Repo -> UrlRenderer -> Remote -> Assistant Bool
|
handleRemoteProblem' :: Git.Repo -> UrlRenderer -> Remote -> Assistant Bool
|
||||||
handleRemoteProblem' repo urlrenderer rmt
|
handleRemoteProblem' repo urlrenderer rmt
|
||||||
| Git.repoIsLocal repo && not (Git.repoIsLocalUnknown repo) =
|
| Git.repoIsLocal repo && not (Git.repoIsLocalUnknown repo) =
|
||||||
ifM (liftIO $ checkAvailable True rmt)
|
ifM (liftAnnex $ checkAvailable True rmt)
|
||||||
( do
|
( do
|
||||||
fixedlocks <- repairStaleGitLocks repo
|
fixedlocks <- repairStaleGitLocks repo
|
||||||
fsckresults <- showFscking urlrenderer (Just rmt) $ tryNonAsync $
|
fsckresults <- showFscking urlrenderer (Just rmt) $ tryNonAsync $
|
||||||
|
|
|
@ -44,7 +44,7 @@ pushThread = namedThread "Pusher" $ runEvery (Seconds 2) <~> do
|
||||||
- to avoid ugly messages when a removable drive is not attached.
|
- to avoid ugly messages when a removable drive is not attached.
|
||||||
-}
|
-}
|
||||||
pushTargets :: Assistant [Remote]
|
pushTargets :: Assistant [Remote]
|
||||||
pushTargets = liftIO . filterM (Remote.checkAvailable True)
|
pushTargets = liftAnnex . filterM (Remote.checkAvailable True)
|
||||||
=<< candidates <$> getDaemonStatus
|
=<< candidates <$> getDaemonStatus
|
||||||
where
|
where
|
||||||
candidates = filter (not . Remote.readonly) . syncGitRemotes
|
candidates = filter (not . Remote.readonly) . syncGitRemotes
|
||||||
|
|
|
@ -411,9 +411,12 @@ byCost = map snd . sortBy (comparing fst) . M.toList . costmap
|
||||||
costmap = M.fromListWith (++) . map costpair
|
costmap = M.fromListWith (++) . map costpair
|
||||||
costpair r = (cost r, [r])
|
costpair r = (cost r, [r])
|
||||||
|
|
||||||
checkAvailable :: Bool -> Remote -> IO Bool
|
checkAvailable :: Bool -> Remote -> Annex Bool
|
||||||
checkAvailable assumenetworkavailable =
|
checkAvailable assumenetworkavailable r = tryNonAsync (availability r) >>= \case
|
||||||
maybe (return assumenetworkavailable) doesDirectoryExist . localpath
|
Left _e -> return assumenetworkavailable
|
||||||
|
Right LocallyAvailable -> return True
|
||||||
|
Right GloballyAvailable -> return assumenetworkavailable
|
||||||
|
Right Unavailable -> return False
|
||||||
|
|
||||||
hasKey :: Remote -> Key -> Annex (Either String Bool)
|
hasKey :: Remote -> Key -> Annex (Either String Bool)
|
||||||
hasKey r k = either (Left . show) Right <$> tryNonAsync (checkPresent r k)
|
hasKey r k = either (Left . show) Right <$> tryNonAsync (checkPresent r k)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue