[Gradle, JS] Handle empty directories in task outputs backups
#KT-52925 Fixed
This commit is contained in:
committed by
Space
parent
10146a7028
commit
e3f6ba4502
+10
-4
@@ -43,7 +43,7 @@ internal class TaskOutputsBackup(
|
|||||||
// Kotlin JS compilation task declares one file from 'destinationDirectory' output as task `@OutputFile'
|
// Kotlin JS compilation task declares one file from 'destinationDirectory' output as task `@OutputFile'
|
||||||
// property. To avoid snapshot sync collisions, each snapshot output directory has also 'index' as prefix.
|
// property. To avoid snapshot sync collisions, each snapshot output directory has also 'index' as prefix.
|
||||||
outputs.toSortedSet().forEachIndexed { index, outputPath ->
|
outputs.toSortedSet().forEachIndexed { index, outputPath ->
|
||||||
if (outputPath.isDirectory && Files.list(outputPath.toPath()).use { it.findFirst().isPresent }) {
|
if (outputPath.isDirectory && !outputPath.isEmptyDirectory) {
|
||||||
compressDirectoryToZip(
|
compressDirectoryToZip(
|
||||||
File(snapshotsDir.get().asFile, index.asSnapshotArchiveName),
|
File(snapshotsDir.get().asFile, index.asSnapshotArchiveName),
|
||||||
outputPath
|
outputPath
|
||||||
@@ -105,11 +105,14 @@ internal class TaskOutputsBackup(
|
|||||||
zip.setLevel(Deflater.NO_COMPRESSION)
|
zip.setLevel(Deflater.NO_COMPRESSION)
|
||||||
outputPath
|
outputPath
|
||||||
.walkTopDown()
|
.walkTopDown()
|
||||||
.filter { !it.isDirectory }
|
.filter { file -> !file.isDirectory || file.isEmptyDirectory }
|
||||||
.forEach { file ->
|
.forEach { file ->
|
||||||
val entry = ZipEntry(file.relativeTo(outputPath).invariantSeparatorsPath)
|
val suffix = if (file.isDirectory) "/" else ""
|
||||||
|
val entry = ZipEntry(file.relativeTo(outputPath).invariantSeparatorsPath + suffix)
|
||||||
zip.putNextEntry(entry)
|
zip.putNextEntry(entry)
|
||||||
file.inputStream().buffered().use { it.copyTo(zip) }
|
if (!file.isDirectory) {
|
||||||
|
file.inputStream().buffered().use { it.copyTo(zip) }
|
||||||
|
}
|
||||||
zip.closeEntry()
|
zip.closeEntry()
|
||||||
}
|
}
|
||||||
zip.flush()
|
zip.flush()
|
||||||
@@ -137,6 +140,9 @@ internal class TaskOutputsBackup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val File.isEmptyDirectory: Boolean
|
||||||
|
get() = !Files.list(toPath()).use { it.findFirst().isPresent }
|
||||||
|
|
||||||
private val Path.normalizedToBeRelative: String
|
private val Path.normalizedToBeRelative: String
|
||||||
get() = if (toString() == "/") "." else toString().removePrefix("/")
|
get() = if (toString() == "/") "." else toString().removePrefix("/")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user