Skip to content

Commit 33377c4

Browse files
committed
fix: update replace regex
1 parent 6f19fe4 commit 33377c4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/extractor/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function layersWithLatestFileModifications(
228228
// if finding a deleted file - trimming to its original file name for excluding it from extractedLayers
229229
// + not adding this file
230230
if (isWhitedOutFile(filename)) {
231-
removedFilesToIgnore.add(filename.replace(/\.wh\./, ""));
231+
removedFilesToIgnore.add(removeWhiteoutPrefix(filename));
232232
continue;
233233
}
234234
// not adding previously found to be whited out files to extractedLayers
@@ -255,18 +255,26 @@ function layersWithLatestFileModifications(
255255
* https://github.com/opencontainers/image-spec/blob/main/layer.md#whiteouts
256256
*/
257257
export function isWhitedOutFile(filename: string) {
258-
const lastSlashIndex = filename.lastIndexOf('/');
259-
258+
const lastSlashIndex = filename.lastIndexOf("/");
259+
260260
if (lastSlashIndex === -1) {
261261
// it's a file name, not a path
262-
return filename.startsWith('.wh.');
262+
return filename.startsWith(".wh.");
263263
} else {
264264
// it's a path, so check the last part
265265
const filenameToCheck = filename.substring(lastSlashIndex + 1);
266-
return filenameToCheck.startsWith('.wh.');
266+
return filenameToCheck.startsWith(".wh.");
267267
}
268268
}
269269

270+
/**
271+
* Remove the .wh. prefix from a whiteout file to get the original filename
272+
*/
273+
export function removeWhiteoutPrefix(filename: string): string {
274+
// Replace .wh. that appears at the start or after the last slash
275+
return filename.replace(/^(.*\/)?\.wh\./, "$1");
276+
}
277+
270278
function isBufferType(type: FileContent): type is Buffer {
271279
return (type as Buffer).buffer !== undefined;
272280
}

test/lib/extractor/index.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ describe("isWhitedOutFile", () => {
5353
expect(isWhitedOutFile("end.wh.")).toBe(false);
5454
expect(isWhitedOutFile("/deeply/nested/path/.wh.present")).toBe(true);
5555
expect(isWhitedOutFile("/the/.wh./in/path/present")).toBe(false);
56-
5756
});
5857
});

0 commit comments

Comments
 (0)