X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Fghc-pkg%2FMain.hs;h=3490b6c18d98d84f8105405b9da8861061dd36ad;hb=47d37047e1f51f32184e7a3b6e68a22c2156ae32;hp=940e4043a412ae06e01979935d1129dbd727bc56;hpb=b990a08bc3da9d5f61f44cb661240ca154fa74d7;p=ghc-hetmet.git diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index 940e404..3490b6c 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -fglasgow-exts -cpp #-} +{-# LANGUAGE PatternGuards, CPP, ForeignFunctionInterface #-} ----------------------------------------------------------------------------- -- -- (c) The University of Glasgow 2004-2009. @@ -38,7 +38,7 @@ import System.Directory ( doesDirectoryExist, getDirectoryContents, import System.Exit ( exitWith, ExitCode(..) ) import System.Environment ( getArgs, getProgName, getEnv ) import System.IO -import System.IO.Error (try) +import System.IO.Error import Data.List import Control.Concurrent @@ -63,8 +63,6 @@ import GHC.ConsoleHandler import System.Posix hiding (fdToHandle) #endif -import IO ( isPermissionError ) - #if defined(GLOB) import System.Process(runInteractiveCommand) import qualified System.Info(os) @@ -719,7 +717,7 @@ changeDBDir verbosity cmds db = do do_cmd (RemovePackage p) = do let file = location db display (installedPackageId p) <.> "conf" when (verbosity > Normal) $ putStrLn ("removing " ++ file) - removeFile file + removeFileSafe file do_cmd (AddPackage p) = do let file = location db display (installedPackageId p) <.> "conf" when (verbosity > Normal) $ putStrLn ("writing " ++ file) @@ -1584,7 +1582,7 @@ withFileAtomic targetFile write_content = do `catchIO` \err -> do exists <- doesFileExist targetFile if exists - then do removeFile targetFile + then do removeFileSafe targetFile -- Big fat hairy race condition renameFile newFile targetFile -- If the removeFile succeeds and the renameFile fails @@ -1594,7 +1592,7 @@ withFileAtomic targetFile write_content = do renameFile newFile targetFile #endif `Exception.onException` do hClose newHandle - removeFile newFile + removeFileSafe newFile where template = targetName <.> "tmp" targetDir | null targetDir_ = "." @@ -1693,3 +1691,9 @@ readUTF8File file = do hSetEncoding h utf8 #endif hGetContents h + +-- removeFileSave doesn't throw an exceptions, if the file is already deleted +removeFileSafe :: FilePath -> IO () +removeFileSafe fn = + removeFile fn `catch` \ e -> + when (not $ isDoesNotExistError e) $ ioError e