Fix nested directory entries: add full ancestor chain to ZIP
Build & Deploy / build-and-deploy (push) Successful in 45s

Previously only the immediate parent directory was added as a ZIP
entry. For deeply nested paths like NAS50TH/TRACKS/WILKES/WILKES.DAT,
only NAS50TH/TRACKS/WILKES/ was created — but NAS50TH/TRACKS/ and
NAS50TH/ were skipped (they're only parents of other directories,
never the immediate parent of a file).

Emscripten's FS.createDirectory() fails if parent doesn't exist,
so intermediate directories must be in the ZIP too.

Now walks up the full ancestor chain with a while loop.
This commit is contained in:
Hermes Agent
2026-05-28 13:37:21 +02:00
parent 5a3500c586
commit 8f14ecb5a1
@@ -293,15 +293,16 @@ public class UploadResource {
Files.walk(extractDir).filter(Files::isRegularFile).forEach(f -> { Files.walk(extractDir).filter(Files::isRegularFile).forEach(f -> {
try { try {
String entryName = extractDir.relativize(f).toString().replace('\\', '/'); String entryName = extractDir.relativize(f).toString().replace('\\', '/');
// Ensure all parent directories have explicit entries // Ensure ALL ancestor directories have explicit entries
// (js-dos Emscripten FS requires explicit directory entries) // (Emscripten FS requires every directory in the chain)
int idx = entryName.lastIndexOf('/'); int idx = entryName.lastIndexOf('/');
if (idx >= 0) { while (idx >= 0) {
String parent = entryName.substring(0, idx + 1); String parent = entryName.substring(0, idx + 1);
if (addedDirs.add(parent)) { if (addedDirs.add(parent)) {
zos.putNextEntry(new java.util.zip.ZipEntry(parent)); zos.putNextEntry(new java.util.zip.ZipEntry(parent));
zos.closeEntry(); zos.closeEntry();
} }
idx = entryName.lastIndexOf('/', idx - 1);
} }
zos.putNextEntry(new java.util.zip.ZipEntry(entryName)); zos.putNextEntry(new java.util.zip.ZipEntry(entryName));
Files.copy(f, zos); Files.copy(f, zos);