Repository navigation
🐛 fix(dirs): refuse to create a literal ~ dir without a home - #578
Merged
Merged
Conversation
gaborbernat
force-pushed
the
fix/tilde-home
branch
5 times, most recently
from
September 25, 2026 15:53
0e96dc0 to
4c46ecc
Compare
When HOME is unset and the uid has no passwd entry, os.path.expanduser returns "~/..." unchanged. With ensure_exists the Unix and macOS app directories then created ./~/.local/share/app and similar trees in the working directory. Media directories had the same bug. tox-dev#561 stopped creating their defaults, yet a user-dirs.dirs entry of "$HOME/Documents" resolved to ~/Documents, and ensure_exists made it. Raise RuntimeError from the shared ensure_exists step when the path starts with "~", as pathlib.Path.expanduser does. Route media creation through that step. Reads return the "~" path as before.
gaborbernat
force-pushed
the
fix/tilde-home
branch
from
September 25, 2026 16:50
4c46ecc to
ce8cdbb
Compare
This was referenced Sep 26, 2026
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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 now 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 has nothing left to catch and goes away.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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 now 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 has nothing left to catch and goes away.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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 has nothing left to catch and goes away.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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 has nothing left to catch and goes away.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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 calls os.path.expanduser directly.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 26, 2026
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 calls os.path.expanduser itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
HOMEunset and no passwd entry for the uid,os.path.expanduserreturns~/...unchanged. Underensure_existsthe Unix and macOS app directories then created a literal~tree, such as./~/.local/share/app, in the working directory. #561 stopped creating the media defaults. Auser-dirs.dirsentry of$HOME/Documentsresolved to~/Documentsand hit the same bug. 🏠Under
ensure_existsplatformdirs raisesRuntimeErrorfor a path that starts with~, the errorpathlib.Path.expanduserraises in the same situation and the Windowsuser_publicshare_dirraises for an unknown home (#546). A caller that setsensure_existsasks for a directory to write to. Without a home any path is a guess, and a temporary directory would lose the data on reboot. App directories and configured media directories share one check, and absolute site directories pass it.Reads without
ensure_existsreturn the~path as before, so callers that compute a path and create nothing see no change.docs/parameters.rstdescribes the behavior.