Skip to content

Commit bbc1b5b

Browse files
committed
chore: restore wh related (out of scope)
1 parent f59fe4a commit bbc1b5b

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

lib/extractor/index.ts

Lines changed: 2 additions & 7 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(filename.replace(/.wh./, ""));
232232
continue;
233233
}
234234
// not adding previously found to be whited out files to extractedLayers
@@ -248,13 +248,8 @@ function layersWithLatestFileModifications(
248248
return extractedLayers;
249249
}
250250

251-
/**
252-
* check if a file is 'whited out', which is shown by
253-
* prefixing the filename with a .wh.
254-
* https://www.madebymikal.com/interpreting-whiteout-files-in-docker-image-layers/
255-
*/
256251
export function isWhitedOutFile(filename: string) {
257-
return filename.includes(".wh.");
252+
return filename.match(/.wh./gm);
258253
}
259254

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

test/lib/extractor/index.spec.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getContentAsString, isWhitedOutFile } from "../../../lib/extractor";
1+
import { getContentAsString } from "../../../lib/extractor";
22
import { ExtractAction, ExtractedLayers } from "../../../lib/extractor/types";
33

44
describe("index", () => {
@@ -18,39 +18,3 @@ describe("index", () => {
1818
expect(result).toEqual("Hello, world!");
1919
});
2020
});
21-
22-
describe("isWhitedOutFile", () => {
23-
test("should return true for files containing .wh. in their path", () => {
24-
expect(isWhitedOutFile("/etc/.wh.hosts")).toBe(true);
25-
expect(isWhitedOutFile("/var/lib/.wh.data")).toBe(true);
26-
expect(isWhitedOutFile("/.wh.config")).toBe(true);
27-
});
28-
29-
test("should return false for files not containing .wh.", () => {
30-
expect(isWhitedOutFile("/etc/hosts")).toBe(false);
31-
expect(isWhitedOutFile("")).toBe(false);
32-
expect(isWhitedOutFile("/")).toBe(false);
33-
});
34-
35-
test("should return false for similar but different patterns", () => {
36-
// make sure the dots are literal and not match all
37-
expect(isWhitedOutFile("/etc/wh.hosts")).toBe(false);
38-
expect(isWhitedOutFile("/etc/.whosts")).toBe(false);
39-
expect(isWhitedOutFile("/etc/whhosts")).toBe(false);
40-
41-
// dots in wrong places
42-
expect(isWhitedOutFile("/etc/.w.h.hosts")).toBe(false);
43-
expect(isWhitedOutFile("/etc/..wh..hosts")).toBe(false);
44-
45-
// case sensitive
46-
expect(isWhitedOutFile("/etc/.WH.hosts")).toBe(false);
47-
expect(isWhitedOutFile("/etc/.Wh.hosts")).toBe(false);
48-
});
49-
50-
test("should handle .wh. at different positions", () => {
51-
expect(isWhitedOutFile(".wh.start")).toBe(true);
52-
expect(isWhitedOutFile("middle.wh.file")).toBe(true);
53-
expect(isWhitedOutFile("end.wh.")).toBe(true);
54-
expect(isWhitedOutFile("/deeply/nested/path/.wh.present")).toBe(true);
55-
});
56-
});

0 commit comments

Comments
 (0)