Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions modules/build/src/main/scala/scala/build/LocalRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ object LocalRepo {
// potential race conditions between initial check and lock acquisition
if !os.exists(repoDir) then
val tmpRepoDir = repoDir / os.up / s".$version.tmp"
try os.remove.all(tmpRepoDir)
catch {
case t: Throwable =>
logger.message(s"Error removing $tmpRepoDir: ${t.getMessage}")
}
os.remove.all(tmpRepoDir)
using(archiveUrl.openStream()) { is =>
using(WrappedZipInputStream.create(new BufferedInputStream(is))) { zis =>
extractZip(zis, tmpRepoDir)
Expand All @@ -101,30 +97,21 @@ object LocalRepo {
val lockFile = dir.resolve(s".lock-$id");
Util.createDirectories(lockFile.getParent)
var channel: FileChannel = null
var lock: FileLock = null

try {
channel = FileChannel.open(
lockFile,
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.DELETE_ON_CLOSE
StandardOpenOption.WRITE
)

var lock: FileLock = null
try {
lock = channel.lock()

try f
finally {
lock.release()
lock = null
channel.close()
channel = null
}
}
finally if (lock != null) lock.release()
lock = channel.lock()
f
}
finally {
if (lock != null) lock.release()
if (channel != null) channel.close()
}
finally if (channel != null) channel.close()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2413,4 +2413,29 @@ abstract class RunTestDefinitions
expect(!res.err.trim().contains(legacyRunnerWarning))
}
}

for (parallelInstancesCount <- Seq(2, 5, 10))
test(
s"run $parallelInstancesCount instances in parallel without local repo"
) {
TestInputs.empty.fromRoot { root =>
val localRepoPath =
os.Path(os.proc(
TestUtil.cli,
"directories",
"--power"
).call().out.text().linesIterator.find(_.startsWith("Local repository:")).getOrElse(
throw new RuntimeException("Local repository line not found in directories output")
).split(":", 2).last.trim())
os.remove.all(localRepoPath)

val processes =
(0 until parallelInstancesCount).map { _ =>
os.proc(TestUtil.cli, "--version")
.spawn(cwd = root)
}.zipWithIndex
processes.foreach { case (p, _) => p.waitFor() }
processes.foreach { case (p, _) => expect(p.exitCode == 0) }
}
}
}