Permalink
Browse files

Ensure that the cabal-install logfile gets closed

cabal was failing with:

$ cabal --config-file=/home/hackage-docs/hackage-docs/build-cache/cabal-config install --enable-documentation --enable-tests --haddock-html-location='http://192.168.142.1:8080/package/$pkg-$version/doc' --haddock-option=--built-in-themes --haddock-contents-location='http://192.168.142.1:8080/package/$pkg-$version' --haddock-hyperlink-source --prefix=/home/hackage-docs/hackage-docs/build-cache HUnit-1.2.5.1
Resolving dependencies...
/home/hackage-docs/hackage-docs/build-cache/local.conf.d/package.cache: openBinaryFile: does not exist (No such file or directory)
cabal: /home/hackage-docs/.cabal/logs/HUnit-1.2.5.1.log: resource busy

as it tried to open the log file for reading when it already had it open
for writing:

open("/home/hackage-docs/.cabal/logs/HUnit-1.2.5.1.log", O_WRONLY|O_CREAT|O_NOCTTY|O_APPEND|O_NONBLOCK, 0666) = 3
open("/home/hackage-docs/.cabal/logs/HUnit-1.2.5.1.log", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 5
close(5)                                = 0
close(3)                                = 0
  • Loading branch information...
1 parent 782a487 commit 9e79aa64d7a76787b8dd2c88906b8c02e6babe48 @igfoo igfoo committed with kosmikus Jul 29, 2012
Showing with 20 additions and 16 deletions.
  1. +20 −16 cabal-install/Distribution/Client/Install.hs
@@ -23,7 +23,7 @@ import Data.List
import Data.Maybe
( isJust, fromMaybe, maybeToList )
import Control.Exception as Exception
- ( handleJust )
+ ( bracket, handleJust )
#if MIN_VERSION_base(4,0,0)
import Control.Exception as Exception
( Exception(toException), catches, Handler(Handler), IOException )
@@ -42,7 +42,7 @@ import System.Directory
import System.FilePath
( (</>), (<.>), takeDirectory )
import System.IO
- ( openFile, IOMode(AppendMode), stdout, hFlush )
+ ( openFile, IOMode(AppendMode), stdout, hFlush, hClose )
import System.IO.Error
( isDoesNotExistError, ioeGetFileName )
@@ -1092,20 +1092,24 @@ installUnpackedPackage verbosity buildLimit installLock numJobs
verbosity' = maybe verbosity snd useLogFile
setup cmd flags = do
- logFileHandle <- case useLogFile of
- Nothing -> return Nothing
- Just (mkLogFileName, _) -> do
- let logFileName = mkLogFileName (packageId pkg)
- logDir = takeDirectory logFileName
- unless (null logDir) $ createDirectoryIfMissing True logDir
- logFile <- openFile logFileName AppendMode
- return (Just logFile)
-
- setupWrapper verbosity
- scriptOptions { useLoggingHandle = logFileHandle
- , useWorkingDir = workingDir }
- (Just pkg)
- cmd flags []
+ Exception.bracket
+ (case useLogFile of
+ Nothing -> return Nothing
+ Just (mkLogFileName, _) -> do
+ let logFileName = mkLogFileName (packageId pkg)
+ logDir = takeDirectory logFileName
+ unless (null logDir) $ createDirectoryIfMissing True logDir
+ logFile <- openFile logFileName AppendMode
+ return (Just logFile))
+ (\mHandle -> case mHandle of
+ Just handle -> hClose handle
+ Nothing -> return ())
+ (\logFileHandle ->
+ setupWrapper verbosity
+ scriptOptions { useLoggingHandle = logFileHandle
+ , useWorkingDir = workingDir }
+ (Just pkg)
+ cmd flags [])
reexec cmd = do
-- look for our on executable file and re-exec ourselves using
-- a helper program like sudo to elevate priviledges:

0 comments on commit 9e79aa6

Please sign in to comment.