Repository navigation
🐛 fix(dirs): only create configured media dirs - #561
Merged
gaborbernat merged 1 commit intoSep 25, 2026
Merged
Conversation
4.11.13 (tox-dev#560) made ensure_exists create every Unix media directory, platform defaults such as ~/Templates and ~/Projects included. On a headless box that fills the home directory with folders the user never made. Without HOME it creates a literal ~ directory in the working directory. A configured directory that is a dangling symlink to an unmounted drive made the getter raise FileExistsError. tox-dev#558 asked for the directory from XDG_DOCUMENTS_DIR to exist after access. A configured XDG path tells platformdirs where the user wants the directory, so it keeps creating those, whether they come from the environment or from user-dirs.dirs, on Unix and macOS alike. Defaults stay untouched, and a dangling link comes back unchanged as it did before 4.11.13. The ensure_exists docs now list which directories it creates.
gaborbernat
force-pushed
the
fix/ensure-exists-app-dirs-only
branch
from
September 25, 2026 04:54
6f6b8eb to
09ca0b9
Compare
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
When HOME is unset and the uid has no passwd entry, as in a container started with an arbitrary --user, 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, which a later `rm -rf ~` cleanup would aim at the real home. Raise RuntimeError from the ensure_exists step when the path still starts with "~", the error pathlib.Path.expanduser raises in the same situation. Reads without ensure_exists keep returning the "~" path, so containers that only look up paths keep working. tox-dev#561 already stopped creating the media directories from their defaults.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
When HOME is unset and the uid has no passwd entry, as in a container started with an arbitrary --user, 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. tox-dev#561 fixed the media directories. Raise RuntimeError from the ensure_exists step when the path still starts with "~", the error pathlib.Path.expanduser raises in the same case. Reads without ensure_exists keep returning the "~" path, so callers that only compute a path see no change.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
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. tox-dev#561 fixed the media directories. Raise RuntimeError from the ensure_exists step when the path starts with "~", the error pathlib.Path.expanduser raises in the same case, and keep returning the "~" path from reads without ensure_exists, so callers that only read the path see no change.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
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. Media creation now uses that step too. Reads return the "~" path as before.
gaborbernat
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
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
added a commit
to gaborbernat/platformdirs
that referenced
this pull request
Sep 25, 2026
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.
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.
4.11.13 (#560) made
ensure_existscreate the Unix media directories to fix #558, where the directory fromXDG_DOCUMENTS_DIRdid not exist after access. It also created the platform defaults. Readinguser_templates_diron a headless box made~/Templates, and with noHOMEit made a literal~directory in the working directory. A configured directory that was a dangling symlink to an unmounted drive made the getter raiseFileExistsError. 🐛This keeps #558 fixed and drops the rest. platformdirs creates a media directory when the user set it, through an
XDG_*_DIRvariable oruser-dirs.dirs, because the user chose that path. Defaults stay as they were before 4.11.13, and macOS follows the same rule because it reads the same XDG settings. The media path ignoresFileExistsError, so a dangling link comes back unchanged. App directories keep raising as before.docs/parameters.rstlists which directoriesensure_existscreates. Windows and Android media directories come from the OS, and platformdirs leaves them alone. ✅