minor robustness fixes in repo cost reordering code

This commit is contained in:
Joey Hess 2013-03-18 13:13:33 -04:00
parent 705cb5a84a
commit 69cc8e83ce
2 changed files with 7 additions and 7 deletions

View file

@ -187,16 +187,16 @@ getRepositoriesReorderR = do
{- Get uuid of the moved item, and the list it was moved within. -} {- Get uuid of the moved item, and the list it was moved within. -}
moved <- fromjs <$> runInputGet (ireq textField "moved") moved <- fromjs <$> runInputGet (ireq textField "moved")
list <- map fromjs <$> lookupGetParams "list[]" list <- map fromjs <$> lookupGetParams "list[]"
void $ liftAnnex $ do liftAnnex $ go list =<< Remote.remoteFromUUID moved
remote <- fromMaybe (error "Unknown UUID") <$> liftAssistant updateSyncRemotes
Remote.remoteFromUUID moved where
go _ Nothing = noop
go list (Just remote) = do
rs <- catMaybes <$> mapM Remote.remoteFromUUID list rs <- catMaybes <$> mapM Remote.remoteFromUUID list
forM_ (reorderCosts remote rs) $ \(r, newcost) -> forM_ (reorderCosts remote rs) $ \(r, newcost) ->
when (Remote.cost r /= newcost) $ when (Remote.cost r /= newcost) $
setRemoteCost r newcost setRemoteCost r newcost
remoteListRefresh void remoteListRefresh
liftAssistant updateSyncRemotes
where
fromjs = toUUID . T.unpack fromjs = toUUID . T.unpack
reorderCosts :: Remote -> [Remote] -> [(Remote, Cost)] reorderCosts :: Remote -> [Remote] -> [(Remote, Cost)]

View file

@ -42,7 +42,7 @@ encryptedRemoteCostAdj = 50
- position longer than the list. - position longer than the list.
-} -}
insertCostAfter :: [Cost] -> Int -> [Cost] insertCostAfter :: [Cost] -> Int -> [Cost]
insertCostAfter [] _ = error "insertCostAfter: empty list" insertCostAfter [] _ = []
insertCostAfter l pos insertCostAfter l pos
| pos < 0 = costBetween 0 (l !! 0) : l | pos < 0 = costBetween 0 (l !! 0) : l
| nextpos > maxpos = l ++ [1 + l !! maxpos] | nextpos > maxpos = l ++ [1 + l !! maxpos]