summaryrefslogtreecommitdiff
path: root/utils/ghc-pkg
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2007-12-14 12:33:45 +0000
committerSimon Marlow <simonmar@microsoft.com>2007-12-14 12:33:45 +0000
commit32b906efc4c6474d8af6fd7be2a3ddac2ae20a16 (patch)
treea62ccf1b4aa659607852e4c1ed2793b4eec26bd3 /utils/ghc-pkg
parent18b15542d69770ca761e0663fde6c6fa52fdb129 (diff)
downloadhaskell-32b906efc4c6474d8af6fd7be2a3ddac2ae20a16.tar.gz
always try to remove the new file before restoring the old one (#1963)
Diffstat (limited to 'utils/ghc-pkg')
-rw-r--r--utils/ghc-pkg/Main.hs13
1 files changed, 6 insertions, 7 deletions
diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
index bdd9c80893..697816eb09 100644
--- a/utils/ghc-pkg/Main.hs
+++ b/utils/ghc-pkg/Main.hs
@@ -693,17 +693,16 @@ savingOldConfig filename io = Exception.block $ do
`Exception.catch` \e -> do
hPutStr stdout ("WARNING: an error was encountered while writing "
++ "the new configuration.\n")
- if restore_on_error
- then do
+ -- remove any partially complete new version:
+ try (removeFile filename)
+ -- and attempt to restore the old one, if we had one:
+ when restore_on_error $ do
hPutStr stdout "Attempting to restore the old configuration... "
do renameFile oldFile filename
hPutStrLn stdout "done."
`catch` \err -> hPutStrLn stdout ("Failed: " ++ show err)
- else do
- -- file did not exist before, so the new one which
- -- might be partially complete.
- try (removeFile filename)
- return ()
+ -- Note the above renameFile sometimes fails on Windows with
+ -- "permission denied", I have no idea why --SDM.
Exception.throwIO e
-----------------------------------------------------------------------------