File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff 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 */
256257export 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
260270function isBufferType ( type : FileContent ) : type is Buffer {
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments