tox-dev / platformdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
https://platformdirs.readthedocs.io
MIT License
594 stars 51 forks source link

Problem with `/run/user` folder in VS Code dev containers with user_runtime_path #315

Open domdomegg opened 1 month ago

domdomegg commented 1 month ago

In VS Code dev containers, there is no /run/user folder in the default Python container.

This means using user_runtime_path and trying to put anything there (or using the ensure_exists argument) will result in a crash, with PermissionError: [Errno 13] Permission denied: '/run/user'.

I'm not certain what the best route forwards is here, and this is not my area of expertise! Some tentative thoughts:

ofek commented 1 month ago

Based on https://specifications.freedesktop.org/basedir-spec/latest/index.html:

If $XDG_RUNTIME_DIR is not set applications should fall back to a replacement directory with similar capabilities and print a warning message. Applications should use this directory for communication and synchronization purposes and should not place larger files in it, since it might reside in runtime memory and cannot necessarily be swapped out to disk.

I think we should provide a different location if it doesn't exist.

ncoghlan commented 1 month ago

https://serverfault.com/questions/388840/good-default-for-xdg-runtime-dir has some decent suggested fallbacks - in particular, creating a folder named after the service/application and logged in user in the system tmp directory.

Since user_runtime_dir takes appname and appauthor parameters, a decent tmp dir fallback folder name would be f"{appauthor}-{appname}-{username}".

When ensure_exists is used, the fallback folder should be explicitly created with 700 permissions when it's outside the user's home directory (and hence won't get user-only permissions by default).