more pure code refactoring
This commit is contained in:
parent
c64b50a0ce
commit
6d3df8a083
3 changed files with 15 additions and 9 deletions
|
@ -101,5 +101,4 @@ shutdown = do
|
||||||
unless (q == GitQueue.empty) $ do
|
unless (q == GitQueue.empty) $ do
|
||||||
showSideAction "Recording state in git..."
|
showSideAction "Recording state in git..."
|
||||||
Annex.queueRun
|
Annex.queueRun
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
13
Command.hs
13
Command.hs
|
@ -184,17 +184,20 @@ filterFiles l = do
|
||||||
if null exclude
|
if null exclude
|
||||||
then return l'
|
then return l'
|
||||||
else do
|
else do
|
||||||
let regexp = compile (toregex exclude) []
|
let regexp = compile (wildsRegex exclude) []
|
||||||
return $ filter (notExcluded regexp) l'
|
return $ filter (notExcluded regexp) l'
|
||||||
where
|
where
|
||||||
notState f = not $ stateDir `isPrefixOf` f
|
notState f = not $ stateDir `isPrefixOf` f
|
||||||
notExcluded r f = case match r f [] of
|
notExcluded r f = case match r f [] of
|
||||||
Nothing -> True
|
Nothing -> True
|
||||||
Just _ -> False
|
Just _ -> False
|
||||||
toregex exclude = "^(" ++ toregex' exclude "" ++ ")"
|
|
||||||
toregex' [] c = c
|
wildsRegex :: [String] -> String
|
||||||
toregex' (w:ws) "" = toregex' ws (wildToRegex w)
|
wildsRegex ws = "^(" ++ wildsRegex' ws "" ++ ")"
|
||||||
toregex' (w:ws) c = toregex' ws (c ++ "|" ++ wildToRegex w)
|
wildsRegex' :: [String] -> String -> String
|
||||||
|
wildsRegex' [] c = c
|
||||||
|
wildsRegex' (w:ws) "" = wildsRegex' ws (wildToRegex w)
|
||||||
|
wildsRegex' (w:ws) c = wildsRegex' ws (c ++ "|" ++ wildToRegex w)
|
||||||
|
|
||||||
{- filter out symlinks -}
|
{- filter out symlinks -}
|
||||||
notSymlink :: FilePath -> IO Bool
|
notSymlink :: FilePath -> IO Bool
|
||||||
|
|
|
@ -104,11 +104,15 @@ readLog file = do
|
||||||
if exists
|
if exists
|
||||||
then do
|
then do
|
||||||
s <- readFile file
|
s <- readFile file
|
||||||
-- filter out any unparsable lines
|
return $ parseLog s
|
||||||
return $ filter (\l -> status l /= Undefined )
|
|
||||||
$ map read $ lines s
|
|
||||||
else return []
|
else return []
|
||||||
|
|
||||||
|
parseLog :: String -> [LogLine]
|
||||||
|
parseLog s = filter parsable $ map read $ lines s
|
||||||
|
where
|
||||||
|
-- some lines may be unparseable, avoid them
|
||||||
|
parsable l = status l /= Undefined
|
||||||
|
|
||||||
{- Writes a set of lines to a log file -}
|
{- Writes a set of lines to a log file -}
|
||||||
writeLog :: FilePath -> [LogLine] -> IO ()
|
writeLog :: FilePath -> [LogLine] -> IO ()
|
||||||
writeLog file ls = safeWriteFile file (unlines $ map show ls)
|
writeLog file ls = safeWriteFile file (unlines $ map show ls)
|
||||||
|
|
Loading…
Reference in a new issue