Commit 42c94195 authored by ian@well-typed.com's avatar ian@well-typed.com
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
parent e168baae
......@@ -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 )
......@@ -1089,20 +1089,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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment