Skip to content

docker-to-squash.py: let pull-build and push-update share the working directory - #9295

Open
linzch3 wants to merge 1 commit into
apache:masterfrom
linzch3:fix-9292-reuse-working-dir
Open

linzch3 wants to merge 1 commit into
apache:masterfrom
linzch3:fix-9292-reuse-working-dir

Conversation

@linzch3

@linzch3 linzch3 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fixes #9292.

get_working_dir never reuses a directory: if dts-work-dir exists it creates dts-work-dir/docker-to-squash instead. pull-build calls it once per image, so the 1st image goes to dts-work-dir, the 2nd to dts-work-dir/docker-to-squash, and the 3rd fails with [Errno 17] File exists. And push-update then looks under dts-work-dir/docker-to-squash and doesn't find what pull-build pulled.

I kept the subdirectory behavior as the default on purpose: most commands (pull-build-push-update, remove-image, add-remove-tag, ...) rm -rf their working directory at the end, so they shouldn't take over an existing directory like --working-dir /tmp.

Changes:

  • get_working_dir(directory, reuse=False): with reuse=True it creates the directory if needed (exist_ok=True) and returns it as is.
  • pull_build and push_update pass reuse=True. Neither of them removes the working directory, and they're meant to be run one after the other on the same --working-dir.

How was the change tested

  • python -m unittest -v test_docker_to_squash in bin/ with Python 3.9: passes.
  • New tests: calling get_working_dir(..., reuse=True) 3 times returns the same dir; the default still uses a subdirectory of an existing dir; and a pull_build run over 3 images (skopeo/manifest calls mocked) puts all of them directly under the working dir, after which push_update looks for dts-work-dir/ubuntu:22.04/manifest.json. With the fix reverted, the pull/push test fails with [Errno 17] File exists: '.../dts-work-dir/docker-to-squash'.

An AI assistant helped draft this change; I reviewed it and take responsibility for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker-to-squash.py: get_working_dir creates a new directory on every call, so push-update cannot find pulled images

1 participant