From b1e6334a313a4aca9e83f079937975e1d8c846d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 26 Aug 2021 11:15:07 +0200 Subject: [PATCH] review fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/angry-planes-visit.md | 4 ++-- .../src/reading/tree/ZipArchiveResponse.ts | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.changeset/angry-planes-visit.md b/.changeset/angry-planes-visit.md index 622a7750f9..5c0a78f0c7 100644 --- a/.changeset/angry-planes-visit.md +++ b/.changeset/angry-planes-visit.md @@ -1,5 +1,5 @@ --- -'@backstage/backend-common': patch +'@backstage/backend-common': minor --- -Disable stripping of ZIP archive +The `ZipArchiveResponse` class now accepts an optional `stripFirstDirectory` parameter. Note that its default value is `false`, which leads to a breaking change in behaviour to previous versions of the class. If you use this class explicitly and want to retain the old behaviour, add a `true` parameter value to its constructor. diff --git a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts index c40557ce94..fb22f24b94 100644 --- a/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts +++ b/packages/backend-common/src/reading/tree/ZipArchiveResponse.ts @@ -38,7 +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, + private readonly stripFirstDirectory?: boolean, ) { if (subPath) { if (!subPath.endsWith('/')) { @@ -68,7 +68,9 @@ export class ZipArchiveResponse implements ReadTreeResponse { } private shouldBeIncluded(entry: Entry): boolean { - const strippedPath = this.stripFirstDirectoryFromPath ? stripFirstDirectoryFromPath(entry.path) : entry.path; + const strippedPath = this.stripFirstDirectory + ? stripFirstDirectoryFromPath(entry.path) + : entry.path; if (this.subPath) { if (!strippedPath.startsWith(this.subPath)) { @@ -100,7 +102,11 @@ export class ZipArchiveResponse implements ReadTreeResponse { if (this.shouldBeIncluded(entry)) { files.push({ - path: this.getInnerPath(this.stripFirstDirectoryFromPath ? stripFirstDirectoryFromPath(entry.path) : entry.path), + path: this.getInnerPath( + this.stripFirstDirectory + ? stripFirstDirectoryFromPath(entry.path) + : entry.path, + ), content: () => entry.buffer(), }); } else { @@ -149,7 +155,9 @@ 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( - this.stripFirstDirectoryFromPath ? stripFirstDirectoryFromPath(entry.path) : entry.path, + this.stripFirstDirectory + ? stripFirstDirectoryFromPath(entry.path) + : entry.path, ); const dirname = platformPath.dirname(entryPath); if (dirname) {