-
Notifications
You must be signed in to change notification settings - Fork 25
fix: CN-272 whiteout regex bug #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bd2c845
6064ac0
cb14317
4f66915
008a8ea
6af7adf
6982327
9670836
84a7096
dc2517f
b8a9b38
ef6a033
e6aa931
12c304f
6a4a4c5
1a0c472
e47f47a
17d541d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,7 +228,7 @@ function layersWithLatestFileModifications( | |
| // if finding a deleted file - trimming to its original file name for excluding it from extractedLayers | ||
| // + not adding this file | ||
| if (isWhitedOutFile(filename)) { | ||
| removedFilesToIgnore.add(filename.replace(/.wh./, "")); | ||
| removedFilesToIgnore.add(removeWhiteoutPrefix(filename)); | ||
| continue; | ||
| } | ||
| // not adding previously found to be whited out files to extractedLayers | ||
|
|
@@ -248,8 +248,32 @@ function layersWithLatestFileModifications( | |
| return extractedLayers; | ||
| } | ||
|
|
||
| /** | ||
| * check if a file is 'whited out', which is shown by | ||
| * prefixing the filename with a .wh. | ||
| * https://www.madebymikal.com/interpreting-whiteout-files-in-docker-image-layers | ||
| * https://github.com/opencontainers/image-spec/blob/main/layer.md#whiteouts | ||
| */ | ||
| export function isWhitedOutFile(filename: string) { | ||
| return filename.match(/.wh./gm); | ||
| const lastSlashIndex = filename.lastIndexOf("/"); | ||
parker-snyk marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this assumes unix path separator -- do we need to handle windows too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just updated to use path.basename so it should account for this now - https://nodejs.org/api/path.html#windows-vs-posix |
||
|
|
||
| if (lastSlashIndex === -1) { | ||
| // it's a file name, not a path | ||
| return filename.startsWith(".wh."); | ||
| } else { | ||
| // it's a path, so check the last part | ||
| const filenameToCheck = filename.substring(lastSlashIndex + 1); | ||
| return filenameToCheck.startsWith(".wh."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Remove the .wh. prefix from a whiteout file to get the original filename | ||
| */ | ||
| export function removeWhiteoutPrefix(filename: string): string { | ||
| // Replace .wh. that appears at the start or after the last slash, | ||
| // and ensure no slashes come after .wh. | ||
| return filename.replace(/^(.*\/)?\.wh\.([^\/]*)$/, "$1$2"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think this should be "+" instead? I guess we expect 0 times to be a bug in the generator (i.e., impossible) but we should still remove it?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The comment applied to the |
||
| } | ||
|
|
||
| function isBufferType(type: FileContent): type is Buffer { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55967,11 +55967,6 @@ Array [ | |
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [], | ||
| "nodeId": "[email protected]", | ||
|
|
@@ -56605,6 +56600,20 @@ Array [ | |
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [ | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| ], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [ | ||
| Object { | ||
|
|
@@ -56637,6 +56646,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| ], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
|
|
@@ -56679,6 +56691,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| ], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
|
|
@@ -57106,6 +57121,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| ], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
|
|
@@ -57584,6 +57602,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| ], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
|
|
@@ -58137,6 +58158,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| ], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
|
|
@@ -58246,6 +58270,11 @@ Array [ | |
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [], | ||
| "nodeId": "[email protected]", | ||
| "pkgId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "deps": Array [], | ||
| "nodeId": "[email protected]", | ||
|
|
@@ -58289,6 +58318,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
|
|
@@ -58316,6 +58348,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
|
|
@@ -58913,9 +58948,6 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
|
|
@@ -59153,6 +59185,9 @@ Array [ | |
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
| Object { | ||
| "nodeId": "[email protected]", | ||
| }, | ||
|
|
@@ -60080,13 +60115,6 @@ Array [ | |
| "version": "3.0.0", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "isexe", | ||
| "version": "2.0.0", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
|
|
@@ -60542,6 +60570,20 @@ Array [ | |
| "version": "4.4.13", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "isexe", | ||
| "version": "2.0.0", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "which", | ||
| "version": "1.3.1", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
|
|
@@ -61550,6 +61592,13 @@ Array [ | |
| "version": "1.0.1", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "which-module", | ||
| "version": "2.0.0", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this function also need to account for opaque whiteouts: https://github.com/opencontainers/image-spec/blob/main/layer.md#opaque-whiteout?
In other words, check that the filename is not
.wh..wh..opq? Looking above, it's not clear our extractor logic even handles opaque whiteouts at all 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as long as it starts with .wh it should account for it, it looks like out logic checks if a file is or within any whited out file or directory, so if a directory starts with .wh, any files under it should be excluded. I can manually verify though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I misunderstood how .wh..wh..opq worked, I'll fix this