Skip to content

main: default to XDG cache directory for non-root users#511

Open
guillermodotn wants to merge 1 commit intoosbuild:mainfrom
guillermodotn:fix/handle-permissions-better
Open

main: default to XDG cache directory for non-root users#511
guillermodotn wants to merge 1 commit intoosbuild:mainfrom
guillermodotn:fix/handle-permissions-better

Conversation

@guillermodotn
Copy link
Copy Markdown

Summary

  • Default the --cache path to $XDG_CACHE_HOME/image-builder/store (or ~/.cache/image-builder/store) when running as a non-root user, instead of the root-only /var/cache/image-builder/store
  • Add an early writability check on the cache directory to fail fast with an actionable hint, instead of waiting for osbuild to fail after manifest generation

Fixes #76

@guillermodotn guillermodotn requested a review from a team as a code owner May 7, 2026 11:19
Copy link
Copy Markdown
Member

@supakeen supakeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you; this is pretty much what I had in mind for this.

Note that we do ship a systemd tmpfiles dropin to clean up /var/cache/image-builder but we don't do this for the new locations. You don't need to address this but I did want to mention it in this PR.

In the future we should grow a image-builder cache ... subcommand to manage/prune the cache.

Copy link
Copy Markdown

@brlane-rht brlane-rht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see tests that always run since right now they are going to miss coverage depending on how they are invoked. The simple solution is to pass in os.Getuid to DefaultCacheDir, but that's kinda ugly.

Comment thread cmd/image-builder/main.go
// waiting for osbuild to fail after slow manifest generation.
if err := os.MkdirAll(cacheDir, 0755); err != nil {
return fmt.Errorf("cannot create cache directory %q: %w\nHint: use --cache to specify a writable path", cacheDir, err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice.

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.

Handle permissions better

4 participants