summaryrefslogtreecommitdiff
path: root/LocationLog.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-09 23:35:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-09 23:35:05 -0400
commit381e6f84e5f4ddc64ed86f08064ebaf2313b18db (patch)
treeb1adc6b70db80856275db0b0328cb484996093ab /LocationLog.hs
parent011118dbdff84458a5f9eea05547d79fbf7e88ac (diff)
robustness
Diffstat (limited to 'LocationLog.hs')
-rw-r--r--LocationLog.hs26
1 files changed, 17 insertions, 9 deletions
diff --git a/LocationLog.hs b/LocationLog.hs
index 911e4765b..b6c85113d 100644
--- a/LocationLog.hs
+++ b/LocationLog.hs
@@ -19,6 +19,7 @@ module LocationLog where
import Data.DateTime
import System.IO
+import System.Directory
import GitRepo
import Utility
@@ -55,22 +56,29 @@ instance Read LogLine where
where
date = fromSeconds $ read $ w !! 0
status = read $ w !! 1
- repo = unwords $ rest w
+ repo = unwords $ drop 2 w
w = words string
- rest (_:_:l) = l
-{- Reads a log file -}
+{- Reads a log file.
+ - Note that the LogLines returned may be in any order. -}
readLog :: String -> IO [LogLine]
readLog file = do
- h <- openLocked file ReadMode
- s <- hGetContents h
- -- hClose handle' -- TODO disabled due to lazy IO issue
- -- filter out any unparsable lines
- return $ filter (\l -> (status l) /= Undefined ) $ map read $ lines s
+ exists <- doesFileExist file
+ if exists
+ then do
+ h <- openLocked file ReadMode
+ s <- hGetContents h
+ -- hClose handle' -- TODO disabled due to lazy IO issue
+ -- filter out any unparsable lines
+ return $ filter (\l -> (status l) /= Undefined )
+ $ map read $ lines s
+ else do
+ return []
{- Adds a LogLine to a log file -}
writeLog :: String -> LogLine -> IO ()
writeLog file line = do
+ createDirectoryIfMissing True (parentDir file)
h <- openLocked file AppendMode
hPutStrLn h $ show line
hClose h
@@ -99,4 +107,4 @@ fileLocations file = do
{- Filters the list of LogLines to find repositories where the file
- is (or should still be) present. -}
filterPresent :: [LogLine] -> [LogLine]
-filterPresent lines =
+filterPresent lines = error "unimplimented" -- TODO