Do not package empty directories (#330)

Changes the packager to exclude any empty directories.

This change means that pkl project package for an already published packages will fail. The packager checks for an existing package at this version, and compares checksums. It will then error if the checksum has changed.

This is technically a breaking change, albeit a minor one. The workaround is to publish new versions of packages.

Published packages should still be compatible with Pkl 0.25.
This commit is contained in:
Stefan M
2024-03-19 17:34:47 +01:00
committed by GitHub
parent 5d0d2ce7a1
commit 46d65506d5
2 changed files with 22 additions and 30 deletions

View File

@@ -278,13 +278,6 @@ public class ProjectPackager {
}
}
private String ensureEndsWithSlash(Path file) {
if (file.endsWith("/")) {
return file.toString();
}
return file + "/";
}
/**
* Sets mtime to 0 so package creation is idempotent. Running the packager multiple times produces
* the same output.
@@ -302,16 +295,10 @@ public class ProjectPackager {
try (var zos = new ZipOutputStream(digestOutputStream)) {
for (var file : files) {
var relativePath = project.getProjectDir().relativize(file);
if (Files.isDirectory(file)) {
var zipEntry = new ZipEntry(ensureEndsWithSlash(relativePath));
zipEntry.setTime(ZIP_ENTRY_MTIME);
zos.putNextEntry(zipEntry);
} else {
var zipEntry = new ZipEntry(relativePath.toString());
zipEntry.setTime(ZIP_ENTRY_MTIME);
zos.putNextEntry(zipEntry);
Files.copy(file, zos);
}
var zipEntry = new ZipEntry(relativePath.toString());
zipEntry.setTime(ZIP_ENTRY_MTIME);
zos.putNextEntry(zipEntry);
Files.copy(file, zos);
zos.closeEntry();
}
} catch (IOException e) {
@@ -344,6 +331,7 @@ public class ProjectPackager {
var excludePatterns = getExcludePatterns(pkg);
try (var stream = Files.walk(project.getProjectDir())) {
return stream
.filter(Files::isRegularFile)
.filter(
(it) -> {
var fileNameRelativeToProjectRoot =