This commit is contained in:
Joey Hess 2011-12-03 09:10:23 -04:00
parent b5930f6d07
commit 64672c6262
5 changed files with 6 additions and 12 deletions

View file

@ -24,3 +24,4 @@ import Utility.Conditional as X
import Utility.SafeCommand as X import Utility.SafeCommand as X
import Utility.Path as X import Utility.Path as X
import Utility.Directory as X import Utility.Directory as X
import Utility.Monad as X

View file

@ -89,11 +89,7 @@ gitAnnexLocation key r
annexLocation key hashDirMixed annexLocation key hashDirMixed
where where
go dir locs = fromMaybe (dir </> head locs) <$> check dir locs go dir locs = fromMaybe (dir </> head locs) <$> check dir locs
check _ [] = return Nothing check dir = firstM $ \f -> doesFileExist $ dir </> f
check dir (l:ls) = do
let f = dir </> l
e <- doesFileExist f
if e then return (Just f) else check dir ls
{- The annex directory of a repository. -} {- The annex directory of a repository. -}
gitAnnexDir :: Git.Repo -> FilePath gitAnnexDir :: Git.Repo -> FilePath

View file

@ -13,7 +13,6 @@ import qualified Git
import Config import Config
import Logs.Web import Logs.Web
import qualified Utility.Url as Url import qualified Utility.Url as Url
import Utility.Monad
remote :: RemoteType Annex remote :: RemoteType Annex
remote = RemoteType { remote = RemoteType {

View file

@ -9,12 +9,6 @@ module Utility.Conditional where
import Control.Monad (when, unless) import Control.Monad (when, unless)
untilTrue :: Monad m => [v] -> (v -> m Bool) -> m Bool
untilTrue [] _ = return False
untilTrue (v:vs) a = do
ok <- a v
if ok then return ok else untilTrue vs a
whenM :: Monad m => m Bool -> m () -> m () whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a whenM c a = c >>= flip when a

View file

@ -24,3 +24,7 @@ firstM p (x:xs) = do
- stopping once one is found. -} - stopping once one is found. -}
anyM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool anyM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool
anyM p = liftM isJust . firstM p anyM p = liftM isJust . firstM p
{- Runs an action on values from a list until it succeeds. -}
untilTrue :: (Monad m) => [a] -> (a -> m Bool) -> m Bool
untilTrue = flip anyM