Skip to content

fix: check the target directory before cutting - #342

Open
aozmekik wants to merge 1 commit into
canonical:mainfrom
aozmekik:fix-target-dir-check
Open

aozmekik wants to merge 1 commit into
canonical:mainfrom
aozmekik:fix-target-dir-check

Conversation

@aozmekik

@aozmekik aozmekik commented Oct 26, 2026 •

Copy link
Copy Markdown
  • Have you signed the CLA?

Fixes #234.

When --root doesn't exist, the cut fails only once it extracts the first package, and the error blames that package instead of the directory:

error: cannot extract from package "base-files": target directory does not exist

This checks the target directory in slicer.Run as suggested on the issue, before any package is fetched:

error: target directory does not exist: /root-fs

A path that exists but isn't a directory now gives target is not a directory: /etc/hosts instead of a mkdir error. The check in tarball stays as it is.

I didn't touch #206: the release and archive indexes are still fetched first (#264 and #288 are changing cmd_cut.go), and creating the directory automatically hasn't been decided. Two new cases in slicer_test.go cover both errors.

When the target directory did not exist, the cut failed with
"cannot extract from package "base-files": target directory does not
exist", which pointed at the first package being extracted rather than
at the directory, and only after the packages were fetched.

Check the target directory at the start of slicer.Run and return an
error that names it, also covering the case where the path exists but is
not a directory. The check in the tarball package is kept, as that
package has its own API.

Fixes canonical#234.
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.

UX: error on 'directory does not exist'

1 participant