set/unset annex-sync, rather than annex-ignore
This reserves annex.ignore for repos that should not be visible at all; repos with syncing disabled are now skipped by the assistant, but are displayed in the list and can be configured.
This commit is contained in:
parent
2602c8f877
commit
0b266f970f
4 changed files with 43 additions and 26 deletions
|
@ -17,6 +17,8 @@ import Utility.NotificationBroadcaster
|
|||
import Logs.Transfer
|
||||
import Logs.Trust
|
||||
import qualified Remote
|
||||
import qualified Types.Remote as Remote
|
||||
import Config
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import System.Posix.Types
|
||||
|
@ -86,10 +88,11 @@ modifyDaemonStatus dstatus a = do
|
|||
sendNotification $ changeNotifier s
|
||||
return b
|
||||
|
||||
{- Remotes ordered by cost, with dead ones thrown out. -}
|
||||
{- Syncable remotes ordered by cost. -}
|
||||
calcKnownRemotes :: Annex [Remote]
|
||||
calcKnownRemotes = do
|
||||
rs <- concat . Remote.byCost <$> Remote.enabledRemoteList
|
||||
rs <- filterM (repoSyncable . Remote.repo) =<<
|
||||
concat . Remote.byCost <$> Remote.enabledRemoteList
|
||||
alive <- snd <$> trustPartition DeadTrusted (map Remote.uuid rs)
|
||||
let good r = Remote.uuid r `elem` alive
|
||||
return $ filter good rs
|
||||
|
|
|
@ -21,6 +21,7 @@ import qualified Types.Remote as Remote
|
|||
import Annex.UUID (getUUID)
|
||||
import Logs.Remote
|
||||
import Logs.Trust
|
||||
import Config
|
||||
|
||||
import Yesod
|
||||
import Data.Text (Text)
|
||||
|
@ -44,21 +45,29 @@ getRepositoriesR = bootstrap (Just Config) $ do
|
|||
repolist <- lift $ repoList False True
|
||||
$(widgetFile "configurators/repositories")
|
||||
|
||||
data SetupRepo = EnableRepo (Route WebApp) | EditRepo (Route WebApp)
|
||||
data SetupRepo =
|
||||
EnableRepo (Route WebApp) |
|
||||
EditRepo (Route WebApp) |
|
||||
EnableSyncRepo (Route WebApp)
|
||||
|
||||
needsEnabled :: SetupRepo -> Bool
|
||||
needsEnabled (EnableRepo _) = True
|
||||
needsEnabled _ = False
|
||||
|
||||
notSyncing :: SetupRepo -> Bool
|
||||
notSyncing (EnableSyncRepo _) = True
|
||||
notSyncing _ = False
|
||||
|
||||
setupRepoLink :: SetupRepo -> Route WebApp
|
||||
setupRepoLink (EnableRepo r) = r
|
||||
setupRepoLink (EditRepo r) = r
|
||||
setupRepoLink (EnableSyncRepo r) = r
|
||||
|
||||
{- A numbered list of known repositories. -}
|
||||
repoList :: Bool -> Bool -> Handler [(String, String, SetupRepo)]
|
||||
repoList onlyconfigured includehere
|
||||
| onlyconfigured = list =<< configured
|
||||
| otherwise = list =<< (++) <$> configured <*> unconfigured
|
||||
| otherwise = list =<< (++) <$> configured <*> rest
|
||||
where
|
||||
configured = do
|
||||
rs <- filter (not . Remote.readonly) . knownRemotes <$>
|
||||
|
@ -67,12 +76,16 @@ repoList onlyconfigured includehere
|
|||
u <- getUUID
|
||||
let l = map Remote.uuid rs
|
||||
let l' = if includehere then u : l else l
|
||||
return $ zip l' (map editlink l')
|
||||
editlink = EditRepo . EditRepositoryR
|
||||
unconfigured = runAnnex [] $ do
|
||||
return $ withlinks (EditRepo . EditRepositoryR) l'
|
||||
withlinks mklink l = zip l (map mklink l)
|
||||
rest = runAnnex [] $ do
|
||||
m <- readRemoteLog
|
||||
catMaybes . map (findtype m) . snd
|
||||
unconfigured <- catMaybes . map (findtype m) . snd
|
||||
<$> (trustPartition DeadTrusted $ M.keys m)
|
||||
unsyncable <- withlinks (EnableSyncRepo . EditRepositoryR) . map Remote.uuid <$>
|
||||
(filterM (\r -> not <$> repoSyncable (Remote.repo r))
|
||||
=<< Remote.enabledRemoteList)
|
||||
return $ unsyncable ++ unconfigured
|
||||
findtype m u = case M.lookup u m of
|
||||
Nothing -> Nothing
|
||||
Just c -> case M.lookup "type" c of
|
||||
|
|
|
@ -27,7 +27,7 @@ import Logs.Group
|
|||
import Logs.PreferredContent
|
||||
import Logs.Transfer
|
||||
import Types.StandardGroups
|
||||
import Config
|
||||
import qualified Config
|
||||
import Annex.UUID
|
||||
|
||||
import Yesod
|
||||
|
@ -42,7 +42,7 @@ data RepoGroup = RepoGroupCustom String | RepoGroupStandard StandardGroup
|
|||
data RepoConfig = RepoConfig
|
||||
{ repoDescription :: Text
|
||||
, repoGroup :: RepoGroup
|
||||
, repoEnabled :: Bool
|
||||
, repoSyncable :: Bool
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
|
@ -50,18 +50,16 @@ getRepoConfig :: Remote -> Annex RepoConfig
|
|||
getRepoConfig r = RepoConfig
|
||||
<$> (T.pack . fromMaybe "" . M.lookup uuid <$> uuidMap)
|
||||
<*> getrepogroup
|
||||
<*> (thisrepo <||> (elem r <$> Remote.enabledRemoteList))
|
||||
<*> Config.repoSyncable (Remote.repo r)
|
||||
where
|
||||
getrepogroup = do
|
||||
groups <- lookupGroups uuid
|
||||
return $
|
||||
maybe (RepoGroupCustom $ unwords $ S.toList groups) RepoGroupStandard
|
||||
(getStandardGroup groups)
|
||||
thisrepo = (==) uuid <$> getUUID
|
||||
uuid = Remote.uuid r
|
||||
|
||||
{- Returns Just False if the repository has been disabled,
|
||||
- or Just True when enabled. -}
|
||||
{- Returns Just False if syncing has been disabled, or Just True when enabled. -}
|
||||
setRepoConfig :: Remote -> RepoConfig -> Annex (Maybe Bool)
|
||||
setRepoConfig r c = do
|
||||
describeUUID uuid $ T.unpack $ repoDescription c
|
||||
|
@ -71,27 +69,27 @@ setRepoConfig r c = do
|
|||
ifM ((==) uuid <$> getUUID)
|
||||
( return Nothing
|
||||
, do
|
||||
enabled <- elem r <$> Remote.enabledRemoteList
|
||||
if (enabled /= repoEnabled c)
|
||||
syncable <- Config.repoSyncable $ Remote.repo r
|
||||
if (syncable /= repoSyncable c)
|
||||
then do
|
||||
setConfig annex_ignore $
|
||||
if enabled then "true" else "false"
|
||||
let key = Config.remoteConfig (Remote.repo r) "sync"
|
||||
Config.setConfig key $
|
||||
if syncable then "false" else "true"
|
||||
void $ Remote.remoteListRefresh
|
||||
return $ Just $ repoEnabled c
|
||||
return $ Just $ repoSyncable c
|
||||
else return Nothing
|
||||
)
|
||||
where
|
||||
uuid = Remote.uuid r
|
||||
annex_ignore = remoteConfig (Remote.repo r) "ignore"
|
||||
|
||||
changeEnabled :: Remote -> Bool -> Handler ()
|
||||
changeEnabled r True = syncRemote r
|
||||
changeEnabled r False = do
|
||||
changeSyncable :: Remote -> Bool -> Handler ()
|
||||
changeSyncable r True = syncRemote r
|
||||
changeSyncable r False = do
|
||||
webapp <- getYesod
|
||||
let dstatus = daemonStatus webapp
|
||||
let st = fromJust $ threadState webapp
|
||||
liftIO $ runThreadState st $ updateKnownRemotes dstatus
|
||||
{- Stop all transfers to or from this disabled remote.
|
||||
{- Stop all transfers to or from this remote.
|
||||
- XXX Can't stop any ongoing scan, or git syncs. -}
|
||||
void $ liftIO $ dequeueTransfers (transferQueue webapp) dstatus tofrom
|
||||
mapM_ (cancelTransfer False) =<<
|
||||
|
@ -104,7 +102,7 @@ editRepositoryAForm :: RepoConfig -> AForm WebApp WebApp RepoConfig
|
|||
editRepositoryAForm def = RepoConfig
|
||||
<$> areq textField "Description" (Just $ repoDescription def)
|
||||
<*> areq (selectFieldList $ customgroups++standardgroups) "Repository group" (Just $ repoGroup def)
|
||||
<*> areq checkBoxField "Syncing enabled" (Just $ repoEnabled def)
|
||||
<*> areq checkBoxField "Syncing enabled" (Just $ repoSyncable def)
|
||||
where
|
||||
standardgroups :: [(Text, RepoGroup)]
|
||||
standardgroups = map (\g -> (T.pack $ descStandardGroup g , RepoGroupStandard g))
|
||||
|
@ -132,7 +130,7 @@ editForm new uuid = bootstrap (Just Config) $ do
|
|||
runFormGet $ renderBootstrap $ editRepositoryAForm curr
|
||||
case result of
|
||||
FormSuccess input -> lift $ do
|
||||
maybe noop (changeEnabled r) =<<
|
||||
maybe noop (changeSyncable r) =<<
|
||||
runAnnex undefined (setRepoConfig r input)
|
||||
redirect RepositoriesR
|
||||
_ -> showform form enctype curr
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
<a href="@{setupRepoLink setuprepo}">
|
||||
enable
|
||||
$else
|
||||
$if notSyncing setuprepo
|
||||
<i>syncing disabled #
|
||||
→ #
|
||||
<a href="@{setupRepoLink setuprepo}">
|
||||
configure
|
||||
<div .row-fluid>
|
||||
|
|
Loading…
Add table
Reference in a new issue