projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix build following haskell98 and -fglasgow-exts changes
[ghc-hetmet.git]
/
utils
/
ghc-pkg
/
Main.hs
diff --git
a/utils/ghc-pkg/Main.hs
b/utils/ghc-pkg/Main.hs
index
e5398ad
..
e42fa4c
100644
(file)
--- a/
utils/ghc-pkg/Main.hs
+++ b/
utils/ghc-pkg/Main.hs
@@
-1,4
+1,4
@@
-{-# OPTIONS -fglasgow-exts -cpp #-}
+{-# LANGUAGE PatternGuards, CPP #-}
-----------------------------------------------------------------------------
--
-- (c) The University of Glasgow 2004-2009.
-----------------------------------------------------------------------------
--
-- (c) The University of Glasgow 2004-2009.
@@
-27,8
+27,6
@@
import Text.Printf
import Prelude
import Prelude
-#include "../../includes/ghcconfig.h"
-
import System.Console.GetOpt
import qualified Control.Exception as Exception
import Data.Maybe
import System.Console.GetOpt
import qualified Control.Exception as Exception
import Data.Maybe
@@
-40,7
+38,7
@@
import System.Directory ( doesDirectoryExist, getDirectoryContents,
import System.Exit ( exitWith, ExitCode(..) )
import System.Environment ( getArgs, getProgName, getEnv )
import System.IO
import System.Exit ( exitWith, ExitCode(..) )
import System.Environment ( getArgs, getProgName, getEnv )
import System.IO
-import System.IO.Error (try)
+import System.IO.Error (try, isDoesNotExistError)
import Data.List
import Control.Concurrent
import Data.List
import Control.Concurrent
@@
-721,7
+719,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)
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)
do_cmd (AddPackage p) = do
let file = location db </> display (installedPackageId p) <.> "conf"
when (verbosity > Normal) $ putStrLn ("writing " ++ file)
@@
-1532,7
+1530,7
@@
installSignalHandlers = do
_ <- installHandler sigQUIT (Catch interrupt) Nothing
_ <- installHandler sigINT (Catch interrupt) Nothing
return ()
_ <- installHandler sigQUIT (Catch interrupt) Nothing
_ <- installHandler sigINT (Catch interrupt) Nothing
return ()
-#elif __GLASGOW_HASKELL__ >= 603
+#else
-- GHC 6.3+ has support for console events on Windows
-- NOTE: running GHCi under a bash shell for some reason requires
-- you to press Ctrl-Break rather than Ctrl-C to provoke
-- GHC 6.3+ has support for console events on Windows
-- NOTE: running GHCi under a bash shell for some reason requires
-- you to press Ctrl-Break rather than Ctrl-C to provoke
@@
-1544,13
+1542,6
@@
installSignalHandlers = do
_ <- installHandler (Catch sig_handler)
return ()
_ <- installHandler (Catch sig_handler)
return ()
-#else
- return () -- nothing
-#endif
-
-#if __GLASGOW_HASKELL__ <= 604
-isInfixOf :: (Eq a) => [a] -> [a] -> Bool
-isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)
#endif
#if mingw32_HOST_OS || mingw32_TARGET_OS
#endif
#if mingw32_HOST_OS || mingw32_TARGET_OS
@@
-1593,7
+1584,7
@@
withFileAtomic targetFile write_content = do
`catchIO` \err -> do
exists <- doesFileExist targetFile
if exists
`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
-- Big fat hairy race condition
renameFile newFile targetFile
-- If the removeFile succeeds and the renameFile fails
@@
-1603,7
+1594,7
@@
withFileAtomic targetFile write_content = do
renameFile newFile targetFile
#endif
`Exception.onException` do hClose newHandle
renameFile newFile targetFile
#endif
`Exception.onException` do hClose newHandle
- removeFile newFile
+ removeFileSafe newFile
where
template = targetName <.> "tmp"
targetDir | null targetDir_ = "."
where
template = targetName <.> "tmp"
targetDir | null targetDir_ = "."
@@
-1644,9
+1635,7
@@
openNewFile dir template = do
oflags = rw_flags .|. o_EXCL
oflags = rw_flags .|. o_EXCL
-#if __GLASGOW_HASKELL__ < 611
withFilePath = withCString
withFilePath = withCString
-#endif
findTempName x = do
fd <- withFilePath filepath $ \ f ->
findTempName x = do
fd <- withFilePath filepath $ \ f ->
@@
-1704,3
+1693,9
@@
readUTF8File file = do
hSetEncoding h utf8
#endif
hGetContents h
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