@@ -16,7 +16,6 @@ import System.Directory (getTemporaryDirectory
1616 , removeFile
1717 , removeDirectoryRecursive
1818 , createDirectoryIfMissing
19− , doesFileExist
2019 )
2120import System.FilePath ((</>), normalise)
2221import System.IO
@@ -66,7 +65,7 @@ isATTY = do
6665withTempdir :: String -> (FilePath -> IO a) -> IO a
6766withTempdir subdir callback
6867 = do dir <- getTemporaryDirectory
69− let tmpDir = (normalise dir) </> subdir
68+ let tmpDir = normalise dir </> subdir
7069 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
7170 (\ ioError -> if isAlreadyExistsError ioError then return False
7271 else throw ioError
@@ -77,12 +76,14 @@ withTempdir subdir callback
7776
7877rmFile :: FilePath -> IO ()
7978rmFile f = do
80− fileExists <- doesFileExist f
81− when fileExists
82− $ do putStrLn $ "Removing " ++ f
83− catchIO (removeFile f)
84− (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
85− ++ f ++ ", Error msg:" ++ show ioerr)
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 ()
85+ | otherwise = putStrLn $ "WARNING: Cannot remove file "
86+ ++ f ++ ", Error msg:" ++ show e
8687
8788setupBundledCC :: IO()
8889#ifdef FREESTANDING