Fixed locking statistics files when multiple gradle daemons started
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ class FileRecordLogger(file: File) : IRecordLogger {
|
||||
|
||||
init {
|
||||
lock = try {
|
||||
channel.lock()
|
||||
channel.tryLock() ?: throw IOException("Could not acquire an exclusive lock of file ${file.name}")
|
||||
} catch (e: Exception) {
|
||||
channel.close()
|
||||
// wrap in order to unify with FileOverlappingException
|
||||
|
||||
+3
-2
@@ -43,9 +43,9 @@ class MetricsContainer : IStatisticsValuesConsumer {
|
||||
|
||||
private val numericalMetricsMap = NumericalMetrics.values().associateBy(NumericalMetrics::name)
|
||||
|
||||
fun readFromFile(file: File, consumer: (MetricsContainer) -> Unit) {
|
||||
fun readFromFile(file: File, consumer: (MetricsContainer) -> Unit): Boolean {
|
||||
val channel = FileChannel.open(Paths.get(file.toURI()), StandardOpenOption.WRITE, StandardOpenOption.READ)
|
||||
channel.lock()
|
||||
channel.tryLock() ?: return false
|
||||
|
||||
val inputStream = Channels.newInputStream(channel)
|
||||
try {
|
||||
@@ -86,6 +86,7 @@ class MetricsContainer : IStatisticsValuesConsumer {
|
||||
} finally {
|
||||
channel.close()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user