Skip to content

🐛 fix(dirs): only create configured media dirs - #561

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/ensure-exists-app-dirs-only
Sep 25, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/ensure-exists-app-dirs-only

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

4.11.13 (#560) made ensure_exists create the Unix media directories to fix #558, where the directory from XDG_DOCUMENTS_DIR did not exist after access. It also created the platform defaults. Reading user_templates_dir on a headless box made ~/Templates, and with no HOME it made a literal ~ directory in the working directory. A configured directory that was a dangling symlink to an unmounted drive made the getter raise FileExistsError. 🐛

This keeps #558 fixed and drops the rest. platformdirs creates a media directory when the user set it, through an XDG_*_DIR variable or user-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 ignores FileExistsError, so a dangling link comes back unchanged. App directories keep raising as before.

docs/parameters.rst lists which directories ensure_exists creates. Windows and Android media directories come from the OS, and platformdirs leaves them alone. ✅

@gaborbernat
gaborbernat requested a review from ofek as a code owner September 25, 2026 04:52
@gaborbernat gaborbernat added the bug Something isn't working label Sep 25, 2026
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
gaborbernat force-pushed the fix/ensure-exists-app-dirs-only branch from 6f6b8eb to 09ca0b9 Compare September 25, 2026 04:54
@gaborbernat
gaborbernat merged commit ae8dea7 into tox-dev:main Sep 25, 2026
36 checks passed
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.
@gaborbernat
gaborbernat deleted the fix/ensure-exists-app-dirs-only branch October 3, 2026 15:12
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.

Unix.user_documents_dir ignores ensure_exists=True for XDG_DOCUMENTS_DIR

1 participant