@@ -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 ( / \. w h \. / , "" ) ) ;
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 */
257257export 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 ( / ^ ( .* \/ ) ? \. w h \. / , "$1" ) ;
276+ }
277+
270278function isBufferType ( type : FileContent ) : type is Buffer {
271279 return ( type as Buffer ) . buffer !== undefined ;
272280}
0 commit comments