on master help sign in
Merge pull request #2820 from Heather/clean
a6d5166David Christiansen
src/Util/System.hs+11−7
@@ -16,9 +16,8 @@ import System.Directory (getTemporaryDirectory
16 , removeFile
16 , removeFile
17 , removeDirectoryRecursive
17 , removeDirectoryRecursive
18 , createDirectoryIfMissing
18 , createDirectoryIfMissing
19− , doesDirectoryExist
20 )
19 )
21−import System.FilePath ((</>), normalise, isAbsolute, dropFileName)
20+import System.FilePath ((</>), normalise)
22import System.IO
21import System.IO
23import System.Info
22import System.Info
24import System.IO.Error
23import System.IO.Error
@@ -66,7 +65,7 @@ isATTY = do
66withTempdir :: String -> (FilePath -> IO a) -> IO a
65withTempdir :: String -> (FilePath -> IO a) -> IO a
67withTempdir subdir callback
66withTempdir subdir callback
68 = do dir <- getTemporaryDirectory
67 = do dir <- getTemporaryDirectory
69− let tmpDir = (normalise dir) </> subdir
68+ let tmpDir = normalise dir </> subdir
70 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
69 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
71 (\ ioError -> if isAlreadyExistsError ioError then return False
70 (\ ioError -> if isAlreadyExistsError ioError then return False
72 else throw ioError
71 else throw ioError
@@ -76,10 +75,15 @@ withTempdir subdir callback
76 return result
75 return result
77
76
78rmFile :: FilePath -> IO ()
77rmFile :: FilePath -> IO ()
79−rmFile f = do putStrLn $ "Removing " ++ f
78+rmFile f = do
80− catchIO (removeFile f)
79+ result <- try (removeFile f)
80+ case result of
81+ Right _ -> putStrLn $ "Removed: " ++ f
82+ Left err -> handleExists err
83+ where handleExists e
84+ | isDoesNotExistError e = return ()
81− (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
85+ | otherwise = putStrLn $ "WARNING: Cannot remove file "
82− ++ f ++ ", Error msg:" ++ show ioerr)
86+ ++ f ++ ", Error msg:" ++ show e
83
87
84setupBundledCC :: IO()
88setupBundledCC :: IO()
85#ifdef FREESTANDING
89#ifdef FREESTANDING