[commit: packages/Cabal] ghc-head: New helper function: removeExistingFile. (8e4227a)
git at git.haskell.org
git at git.haskell.org
Mon Aug 26 23:26:04 CEST 2013
Repository : ssh://git@git.haskell.org/Cabal
On branch : ghc-head
Link : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=8e4227ac8a4f41cc09da00f2bc6adcb045dd175f
>---------------------------------------------------------------
commit 8e4227ac8a4f41cc09da00f2bc6adcb045dd175f
Author: Mikhail Glushenkov <mikhail.glushenkov at gmail.com>
Date: Wed May 29 01:15:14 2013 +0200
New helper function: removeExistingFile.
>---------------------------------------------------------------
8e4227ac8a4f41cc09da00f2bc6adcb045dd175f
cabal-install/Distribution/Client/Utils.hs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/cabal-install/Distribution/Client/Utils.hs b/cabal-install/Distribution/Client/Utils.hs
index 49c5f2c..20c6e05 100644
--- a/cabal-install/Distribution/Client/Utils.hs
+++ b/cabal-install/Distribution/Client/Utils.hs
@@ -3,11 +3,14 @@
module Distribution.Client.Utils ( MergeResult(..)
, mergeBy, duplicates, duplicatesBy
, moreRecentFile, inDir, numberOfProcessors
+ , removeExistingFile
, makeAbsoluteToCwd, filePathToByteString
, byteStringToFilePath, tryCanonicalizePath)
where
import qualified Data.ByteString.Lazy as BS
+import Control.Monad
+ ( when )
import Data.Bits
( (.|.), shiftL, shiftR )
import Data.Char
@@ -21,7 +24,7 @@ import qualified Control.Exception as Exception
( finally )
import System.Directory
( canonicalizePath, doesFileExist, getModificationTime
- , getCurrentDirectory, setCurrentDirectory )
+ , getCurrentDirectory, removeFile, setCurrentDirectory )
import System.FilePath
( (</>), isAbsolute )
import System.IO.Unsafe ( unsafePerformIO )
@@ -74,6 +77,14 @@ moreRecentFile a b = do
ta <- getModificationTime a
return (ta > tb)
+-- | Like 'removeFile', but does not throw an exception when the file does not
+-- exist.
+removeExistingFile :: FilePath -> IO ()
+removeExistingFile path = do
+ exists <- doesFileExist path
+ when exists $
+ removeFile path
+
-- | Executes the action in the specified directory.
inDir :: Maybe FilePath -> IO a -> IO a
inDir Nothing m = m
More information about the ghc-commits
mailing list