adrg / xdg Goto Github PK
View Code? Open in Web Editor NEWGo implementation of the XDG Base Directory Specification and XDG user directories
Home Page: https://pkg.go.dev/github.com/adrg/xdg
License: MIT License
Go implementation of the XDG Base Directory Specification and XDG user directories
Home Page: https://pkg.go.dev/github.com/adrg/xdg
License: MIT License
Lines 57 to 60 in aad56ae
Shouldn't this just give an error? It feels like deleting a file without "consent" is a bit harsh.
Function homeDir
from all paths_{windows | darwin | unix | plan9}.go
does exactly the same thing as os.UserHomeDir. I believe it can be moved to a commons.go
file to reduce the amount of os specific code and rely more on built-in functionality.
~/Library/Preferences is reserved for .plist files - one should never create application-specific subdirectories in there, but each application is supposed to just have ONE .plist file in there, named using its bundle ID.
This differs from XDG_CONFIG_HOME as that one expects per-app directories.
See also:
Instead, XDG_CONFIG_HOME should be ~/Library/Application Support, too.
When building my project Mycorrhiza, a user complained that it doesn't build on Plan 9 operating system. From the error messages I understood that the problem is that initBaseDirs
and initUserDirs
is not implemented for Plan 9, I'd love to see that implemented.
I was upgrading today from v0.0.0-20190319220657-88e5137d2444
to v0.4.0
and my app broke, because DataDirs
is still present but doesn't seem to be used anymore (removed here: 1be1d4f#diff-5c0868fc869fb66c2b33ba837118f18c43f5002d0a3f8b9e11aceabe703d4b86L98)
I suggest dropping it altogether to prevent further confusion.
It would be great if you could provide a function func CacheDir(appname string) (string, error)
that (in contrast to CacheFile
) only creates the cache dir for appname
.
What do you think?
Please also support those directories:
Hi, I have noticed that it might not be correct to create all directories with 0o700
permissions:
xdg/internal/pathutil/pathutil.go
Lines 52 to 54 in d31002f
To be specific, the permission of XDG_RUNTIME_DIR
is supposed to be 700
but its parent, usually /run/user/
, is not. And if above code runs in a part of system daemon and has root privileges, some services that run as normal user may crash. This issue occurs when the system doesn't previously set up /run/user/
, hence it's created alongside app/
.
I am testing this library using fedora and arch Linux and it seems like none of the distributions are setting the env vars for XDG User Directories.
[a@localhost-live test]$ cat /home/a/.config/user-dirs.dirs
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/Pulpit"
XDG_DOWNLOAD_DIR="$HOME/Pobrane"
XDG_TEMPLATES_DIR="$HOME/Szablony"
XDG_PUBLICSHARE_DIR="$HOME/Publiczny"
XDG_DOCUMENTS_DIR="$HOME/Dokumenty"
XDG_MUSIC_DIR="$HOME/Muzyka"
XDG_PICTURES_DIR="$HOME/Obrazy"
XDG_VIDEOS_DIR="$HOME/Wideo"
[a@localhost-live test]$ ./main
2022/02/04 18:14:32 Desktop directory: /home/a/Desktop
2022/02/04 18:14:32 Download directory: /home/a/Downloads
2022/02/04 18:14:32 Documents directory: /home/a/Documents
2022/02/04 18:14:32 Music directory: /home/a/Music
2022/02/04 18:14:32 Pictures directory: /home/a/Pictures
2022/02/04 18:14:32 Videos directory: /home/a/Videos
2022/02/04 18:14:32 Templates directory: /home/a/Templates
2022/02/04 18:14:32 Public directory: /home/a/Public
Firefox for example reads the ~/.config/user-dirs.dirs directly.
[a@localhost-live test]$ cat firefox-strace | grep .config/user-dirs
openat(AT_FDCWD, "/home/a/.config/user-dirs.dirs", O_RDONLY) = 53
Lines 52 to 55 in aad56ae
I think this should give an error with wrong permissions, and not try to set permissions on it own. This path could already contain files from other programs, that "by error" rely on these permissions, and by changing them maybe break them.
Windows has it's own user defined paths. It can be easily found using "golang.org/x/sys/windows" package.
We should check if that path exists, as we shouldn't create this "part" of the folder imho.
As in all the folders in the name
variable is okay to create, but the folders in the paths
could be system folders.
A "constructed" case would be a root user running a program with this, might end up creating /usr/local/share, even if /usr/share is the only path there.
I understand that this would create a problem with paths like ~/.local/state as that wouldn't be created, and I could see a reason for that to be created.
A solution to this might be a few functions to create the XDG_BASE places, and let createPath
only handle the relative part.
func main() {
// For homes that we need to create files in
xdg.CreateCacheHome()
xdg.CreateConfigHome()
}
Lines 63 to 71 in aad56ae
Hello @adrg! Would you be interested in a pull request that enabled custom file system support? (e.g. afero
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.