From a365f1faf4dbb262062775e3d000dd93c5851235 Mon Sep 17 00:00:00 2001 From: Bartosz Nadworny Date: Wed, 25 Aug 2021 14:30:40 +0200 Subject: [PATCH] Disable default stripping of ZIP archive Signed-off-by: Bartosz Nadworny --- .changeset/angry-planes-visit.md | 5 +++++ .../backend-common/src/reading/tree/ZipArchiveResponse.ts | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/angry-planes-visit.md diff --git a/.changeset/angry-planes-visit.md b/.changeset/angry-planes-visit.md new file mode 100644 index 0000000000..622a7750f9 --- /dev/null +++ b/.changeset/angry-planes-visit.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-common': patch +--- + +Disable stripping of ZIP archive diff --git a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts index 5c12a383ee..c40557ce94 100644 --- a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts +++ b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts @@ -38,6 +38,7 @@ export class ZipArchiveResponse implements ReadTreeResponse { private readonly workDir: string, public readonly etag: string, private readonly filter?: (path: string, info: { size: number }) => boolean, + private readonly stripFirstDirectoryFromPath?: boolean, ) { if (subPath) { if (!subPath.endsWith('/')) { @@ -67,7 +68,7 @@ export class ZipArchiveResponse implements ReadTreeResponse { } private shouldBeIncluded(entry: Entry): boolean { - const strippedPath = stripFirstDirectoryFromPath(entry.path); + const strippedPath = this.stripFirstDirectoryFromPath ? stripFirstDirectoryFromPath(entry.path) : entry.path; if (this.subPath) { if (!strippedPath.startsWith(this.subPath)) { @@ -99,7 +100,7 @@ export class ZipArchiveResponse implements ReadTreeResponse { if (this.shouldBeIncluded(entry)) { files.push({ - path: this.getInnerPath(stripFirstDirectoryFromPath(entry.path)), + path: this.getInnerPath(this.stripFirstDirectoryFromPath ? stripFirstDirectoryFromPath(entry.path) : entry.path), content: () => entry.buffer(), }); } else { @@ -148,7 +149,7 @@ export class ZipArchiveResponse implements ReadTreeResponse { // as a zip can have files with directories without directory entries if (entry.type === 'File' && this.shouldBeIncluded(entry)) { const entryPath = this.getInnerPath( - stripFirstDirectoryFromPath(entry.path), + this.stripFirstDirectoryFromPath ? stripFirstDirectoryFromPath(entry.path) : entry.path, ); const dirname = platformPath.dirname(entryPath); if (dirname) {