Disable default stripping of ZIP archive

Signed-off-by: Bartosz Nadworny <bartosz.nadworny@zurich.ch>
This commit is contained in:
Bartosz Nadworny
2021-08-25 14:30:40 +02:00
committed by Bartosz Nadworny
parent 8576195e38
commit a365f1faf4
2 changed files with 9 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Disable stripping of ZIP archive
@@ -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) {