docker-squash icon indicating copy to clipboard operation
docker-squash copied to clipboard

Replacing directory with a regular file breaks squashing

Open Nixxx11 opened this issue 7 months ago • 0 comments

FROM busybox:1.36.1
RUN mkdir /tmp/dir
RUN touch /tmp/dir/file
RUN rm -rf /tmp/dir ; touch /tmp/dir

Squashing this image will produce a broken image containing both /tmp/dir/file and /tmp/dir (second one is a regular file, not a directory). This problem was solved earlier for symlinks (https://github.com/goldmann/docker-squash/issues/120 ?), but it is exactly the same for all other types of files

And here is a similar scenario for marker files:

FROM busybox:1.36.1
RUN mkdir /tmp/dir
RUN touch /tmp/dir/file
RUN rm /tmp/dir/file
RUN rm -rf /tmp/dir ; touch /tmp/dir

Here we will have both /tmp/dir/.wh.file and /tmp/dir. I guess this situation is similar to https://github.com/goldmann/docker-squash/issues/122

The correct solution would be something like this:

  1. Memorize all files we already added
  2. Memorize all directories we already added
  3. When adding a new file, check whether parent directory already exists or not; if it does and it is not actually a directory, skip the file; otherwise, add the file as normal

Nixxx11 avatar May 14 '25 13:05 Nixxx11