From bb4a45f9ce9ea3b5b024bc6e46ab61b7b493de9b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 12 Jan 2011 01:57:49 -0400 Subject: [PATCH] avoid crashing if run before unused log is present --- Command/DropUnused.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index ea2ff46eba..cfd6fc3d0e 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -9,6 +9,7 @@ module Command.DropUnused where import Control.Monad.State (liftIO) import qualified Data.Map as M +import System.Directory import Command import Types @@ -39,8 +40,13 @@ start s = do readUnusedLog :: Annex (M.Map String Key) readUnusedLog = do g <- Annex.gitRepo - l <- liftIO $ readFile (annexUnusedLog g) - return $ M.fromList $ map parse $ lines l + let f = annexUnusedLog g + e <- liftIO $ doesFileExist f + if e + then do + l <- liftIO $ readFile f + return $ M.fromList $ map parse $ lines l + else return $ M.empty where parse line = (head ws, tokey $ unwords $ tail ws) where