mirror of https://github.com/sbt/sbt.git
Fix file descriptor leak.
Close an InputStream when finished reading it. When given an OutputStream to connect to a process input, close it when the transfer is completed. Protect System.in in this latter case.
This commit is contained in:
parent
101fe06510
commit
a3c745a4e6
|
|
@ -51,7 +51,6 @@ object BasicIO
|
||||||
private def processErrFully(log: ProcessLogger) = processFully(s => log.error(s))
|
private def processErrFully(log: ProcessLogger) = processFully(s => log.error(s))
|
||||||
private def processInfoFully(log: ProcessLogger) = processFully(s => log.info(s))
|
private def processInfoFully(log: ProcessLogger) = processFully(s => log.info(s))
|
||||||
|
|
||||||
def ignoreOut = (i: OutputStream) => ()
|
|
||||||
final val BufferSize = 8192
|
final val BufferSize = 8192
|
||||||
final val Newline = System.getProperty("line.separator")
|
final val Newline = System.getProperty("line.separator")
|
||||||
|
|
||||||
|
|
@ -62,6 +61,7 @@ object BasicIO
|
||||||
{
|
{
|
||||||
val reader = new BufferedReader(new InputStreamReader(in))
|
val reader = new BufferedReader(new InputStreamReader(in))
|
||||||
processLinesFully(processLine)(reader.readLine)
|
processLinesFully(processLine)(reader.readLine)
|
||||||
|
reader.close()
|
||||||
}
|
}
|
||||||
def processLinesFully(processLine: String => Unit)(readLine: () => String)
|
def processLinesFully(processLine: String => Unit)(readLine: () => String)
|
||||||
{
|
{
|
||||||
|
|
@ -76,8 +76,11 @@ object BasicIO
|
||||||
}
|
}
|
||||||
readFully()
|
readFully()
|
||||||
}
|
}
|
||||||
def connectToIn(o: OutputStream) { transferFully(System.in, o) }
|
def connectToIn(o: OutputStream) { transferFully(Uncloseable protect System.in, o) }
|
||||||
def input(connect: Boolean): OutputStream => Unit = if(connect) connectToIn else ignoreOut
|
def input(connect: Boolean): OutputStream => Unit = { outputToProcess =>
|
||||||
|
if(connect) connectToIn(outputToProcess)
|
||||||
|
else outputToProcess.close()
|
||||||
|
}
|
||||||
def standard(connectInput: Boolean): ProcessIO = standard(input(connectInput))
|
def standard(connectInput: Boolean): ProcessIO = standard(input(connectInput))
|
||||||
def standard(in: OutputStream => Unit): ProcessIO = new ProcessIO(in, toStdOut, toStdErr)
|
def standard(in: OutputStream => Unit): ProcessIO = new ProcessIO(in, toStdOut, toStdErr)
|
||||||
|
|
||||||
|
|
@ -110,6 +113,7 @@ object BasicIO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
read
|
read
|
||||||
|
in.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -469,4 +473,4 @@ private object Streamed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class Streamed[T](val process: T => Unit, val done: Int => Unit, val stream: () => Stream[T]) extends NotNull
|
private final class Streamed[T](val process: T => Unit, val done: Int => Unit, val stream: () => Stream[T]) extends NotNull
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue