From 3092806838fe337c7d2e8089430e7d464cef4c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Frinnstr=C3=B6m?= Date: Wed, 18 Nov 2020 16:28:27 +0100 Subject: [PATCH] Support ZIP files without directory entries --- .../src/reading/__fixtures__/repo.zip | Bin 629 -> 387 bytes .../src/reading/tree/ZipArchiveResponse.ts | 13 ++++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/backend-common/src/reading/__fixtures__/repo.zip b/packages/backend-common/src/reading/__fixtures__/repo.zip index 47956335edad571c8153646cd5288916c9d8e5f4..f66bf2d612eafc3c4b65216b83d1b3e884726236 100644 GIT binary patch literal 387 zcmWIWW@h1H0D*0_(Sg%M&PT8V*&r;=Aj6QGpPa2*lv0=yB1 jV>%w$@CX#ck-Y*m8RQiVlUdn74q^hr?Lc}Ph{FH?Ktx*D literal 629 zcmWIWW@Zs#0D+CQ(ScwFl;8r=x%tW2x<#o4`T7BHb=%O?@uR3q$xki@D+Xz2U;rte zCUQQ49mob@aUez*3Raw%my%kcmz$!j5RzJ4!UeJjqIUyO@7K0B`vib`Kp5mqgx=h2 zkZ!%o+??XflGOOT#N1RXm-p=~S=0I>~^!vFvP diff --git a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts index 048b2ab46d..89f9803bd2 100644 --- a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts +++ b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts @@ -136,13 +136,16 @@ export class ZipArchiveResponse implements ReadTreeResponse { if (this.shouldBeIncluded(entry)) { const entryPath = this.getPath(entry); if (entry.type === 'Directory') { - if (entryPath) { - fs.mkdirSync(path.join(dir, entryPath)); - } + // Ignore directory entries since we handle that with the file entries + // since a zip can have files with directories without directory entries entry.resume(); - } else { - entry.pipe(fs.createWriteStream(path.join(dir, entryPath))); + return; } + const dirname = path.dirname(entryPath); + if (dirname) { + fs.mkdirSync(path.join(dir, dirname), { recursive: true }); + } + entry.pipe(fs.createWriteStream(path.join(dir, entryPath))); } else { entry.autodrain(); }