Skip to content

🐛 fix(dirs): raise when no home directory resolves - #589

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/no-home
Sep 26, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/no-home

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

With HOME set to an empty string, os.path.expanduser puts the path under /, so Unix().user_config_dir returned /.config/app and the macOS user_data_dir returned /Library/Application Support/app, the shared site directory. 🏠 With HOME unset and no password database entry for the uid, the same properties returned relative paths such as ~/.config/app that resolve against the working directory. #578 guarded only ensure_exists.

Rust's std::env::home_dir treats an empty HOME as unset, and platformdirs does the same, so the password database supplies the home. When neither gives one, each Unix and macOS directory under the home raises RuntimeError on read, as Go's os.UserHomeDir returns an error for an unset or empty HOME. Site directories and absolute XDG values keep resolving. The ~ expansion for both platforms lives in one place and adds a HOME check before os.path.expanduser; the #578 check under ensure_exists stays for iOS, which calls os.path.expanduser itself.

⚠️ Reading a home-based directory without a home raises. That covers a process started with HOME removed or emptied, as with env -i or subprocess given a bare env, for a uid without a password database entry, and an unset HOME on a Python built without pwd, as CPython's WASI build is. On macOS site_runtime_dir equals user_runtime_dir and raises with it, and the iter_*_dirs helpers raise on the user directory they yield first, except the Unix iter_runtime_dirs. Docker containers run with --user for an unknown uid keep getting /.config/app, because runc sets HOME=/ when the passwd lookup fails. An empty HOME with a password database entry resolves to that entry's home.

@gaborbernat
gaborbernat requested a review from ofek as a code owner September 26, 2026 02:27
@gaborbernat gaborbernat added the bug Something isn't working label Sep 26, 2026
@gaborbernat
gaborbernat force-pushed the fix/no-home branch 4 times, most recently from 298b467 to 0464a53 Compare September 26, 2026 14:27
@gaborbernat
gaborbernat enabled auto-merge (squash) September 26, 2026 14:31
With HOME set to an empty string, os.path.expanduser puts the path under
/, so Unix returned /.config/app and macOS returned /Library/Application
Support/app, the shared site directory. With HOME unset and no passwd
entry for the uid, it returns ~/... unchanged and the properties handed
back relative paths such as ~/.config/app. tox-dev#578 guarded ensure_exists
only.

Rust's std::env::home_dir treats an empty HOME as unset, and
platformdirs does the same, so the password database supplies the home.
When neither gives one, each Unix and macOS directory under the home
raises RuntimeError on read, where Go's os.UserHomeDir also returns an
error. Site directories and absolute XDG values keep resolving. One
helper expands ~ for both platforms; the tox-dev#578 check under ensure_exists
stays for iOS, which still calls os.path.expanduser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant