[Gradle] cleanNativeDistributionCommonization: Don't try to delete .lock file
^KT-52172 Verification Pending
This commit is contained in:
committed by
Space Team
parent
8a01ad9010
commit
151da98331
+3
-2
@@ -153,8 +153,9 @@ internal val Project.cleanNativeDistributionCommonizerTask: TaskProvider<Default
|
||||
outputs.dir(commonizerDirectory)
|
||||
|
||||
doFirst {
|
||||
NativeDistributionCommonizerLock(commonizerDirectory.get()).withLock {
|
||||
delete(commonizerDirectory.get())
|
||||
NativeDistributionCommonizerLock(commonizerDirectory.get()).withLock { lockFile ->
|
||||
val files = commonizerDirectory.get().listFiles().orEmpty().toSet() - lockFile
|
||||
delete(*files.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -19,29 +19,29 @@ internal class NativeDistributionCommonizerLock(
|
||||
val lockedOutputDirectories = hashSetOf<File>()
|
||||
}
|
||||
|
||||
fun <T> withLock(action: () -> T): T {
|
||||
fun <T> withLock(action: (lockFile: File) -> T): T {
|
||||
/* Enter intra-process wide lock */
|
||||
intraProcessLock.withLock {
|
||||
val lockFile = outputDirectory.resolve(".lock")
|
||||
if (outputDirectory in lockedOutputDirectories) {
|
||||
/* Already acquired this directory and re-entered: We can just execute the action */
|
||||
return action()
|
||||
return action(lockFile)
|
||||
}
|
||||
|
||||
/* Lock output directory inter-process wide */
|
||||
outputDirectory.mkdirs()
|
||||
val lockfile = outputDirectory.resolve(".lock")
|
||||
logInfo("Acquire lock: ${lockfile.path} ...")
|
||||
logInfo("Acquire lock: ${lockFile.path} ...")
|
||||
FileOutputStream(outputDirectory.resolve(".lock")).use { stream ->
|
||||
val lock = stream.channel.lock()
|
||||
assert(lock.isValid)
|
||||
return try {
|
||||
logInfo("Lock acquired: ${lockfile.path}")
|
||||
logInfo("Lock acquired: ${lockFile.path}")
|
||||
lockedOutputDirectories.add(outputDirectory)
|
||||
action()
|
||||
action(lockFile)
|
||||
} finally {
|
||||
lockedOutputDirectories.remove(outputDirectory)
|
||||
lock.release()
|
||||
logInfo("Lock released: ${lockfile.path}")
|
||||
logInfo("Lock released: ${lockFile.path}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user