on master help sign in
Merge pull request #2820 from Heather/clean

rmFile: don't even try removing not existing files

commita6d5166a520a8c33250a116e067942e640663ed9 authorDavid Christiansen <david@davidchristiansen.dk> dateThu 26 Nov 2015, 22:36 (11 years ago) parent140d06ab11c204
1 file changed+11−7
src/Util/System.hs+11−7
src/Util/System.hs+11−7
@@ -16,9 +16,8 @@ import System.Directory (getTemporaryDirectory
1616 , removeFile
1717 , removeDirectoryRecursive
1818 , createDirectoryIfMissing
19− , doesDirectoryExist
2019 )
21−import System.FilePath ((</>), normalise, isAbsolute, dropFileName)
20+import System.FilePath ((</>), normalise)
2221import System.IO
2322import System.Info
2423import System.IO.Error
@@ -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
@@ -76,10 +75,15 @@ withTempdir subdir callback
7675 return result
7776
7877rmFile :: FilePath -> IO ()
79−rmFile f = do putStrLn $ "Removing " ++ f
80− catchIO (removeFile f)
81− (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
82− ++ f ++ ", Error msg:" ++ show ioerr)
78+rmFile f = do
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
8387
8488setupBundledCC :: IO()
8589#ifdef FREESTANDING