docker-squash
docker-squash copied to clipboard
Replacing directory with a regular file breaks squashing
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:
- Memorize all files we already added
- Memorize all directories we already added
- 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