Skip to content

Commit 6f19fe4

Browse files
committed
fix: update check to follow .wh. specs
1 parent 1e080f2 commit 6f19fe4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/extractor/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,20 @@ function layersWithLatestFileModifications(
251251
/**
252252
* check if a file is 'whited out', which is shown by
253253
* prefixing the filename with a .wh.
254-
* https://www.madebymikal.com/interpreting-whiteout-files-in-docker-image-layers/
254+
* https://www.madebymikal.com/interpreting-whiteout-files-in-docker-image-layers
255+
* https://github.com/opencontainers/image-spec/blob/main/layer.md#whiteouts
255256
*/
256257
export function isWhitedOutFile(filename: string) {
257-
return filename.includes(".wh.");
258+
const lastSlashIndex = filename.lastIndexOf('/');
259+
260+
if (lastSlashIndex === -1) {
261+
// it's a file name, not a path
262+
return filename.startsWith('.wh.');
263+
} else {
264+
// it's a path, so check the last part
265+
const filenameToCheck = filename.substring(lastSlashIndex + 1);
266+
return filenameToCheck.startsWith('.wh.');
267+
}
258268
}
259269

260270
function isBufferType(type: FileContent): type is Buffer {

test/lib/extractor/index.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ describe("isWhitedOutFile", () => {
4949

5050
test("should handle .wh. at different positions", () => {
5151
expect(isWhitedOutFile(".wh.start")).toBe(true);
52-
expect(isWhitedOutFile("middle.wh.file")).toBe(true);
53-
expect(isWhitedOutFile("end.wh.")).toBe(true);
52+
expect(isWhitedOutFile("middle.wh.file")).toBe(false);
53+
expect(isWhitedOutFile("end.wh.")).toBe(false);
5454
expect(isWhitedOutFile("/deeply/nested/path/.wh.present")).toBe(true);
55+
expect(isWhitedOutFile("/the/.wh./in/path/present")).toBe(false);
56+
5557
});
5658
});

0 commit comments

Comments
 (0)