rust-lang / rfcs

RFCs for changes to Rust
https://rust-lang.github.io/rfcs/
Apache License 2.0
5.96k stars 1.57k forks source link

Add a function to access application data directory #1159

Open thelink2012 opened 9 years ago

thelink2012 commented 9 years ago

Currently there is only a way to easily store application specific data using the standard library, std::env::home_dir. That's not a quite correct way. I was thinking about the addition of a std::env::appdata_dir function?

The home directory is only suitable for storing application data on Linux (and perhaps other *nixes?), on Windows the correct place is %AppData% or %LocalAppData% and on OSX it seems to be ~/Library/Preferences/ or ~/Library/Application Support/.

That brought my attention when I noticed that Cargo stores it's data on %USERPROFILE%/.cargo/ _(std::env::home_dir gives%USERPROFILE on Windows)_, note how directories starting with . aren't hidden on Windows and those pollute the user profile directory.

However I have a few concerns about this myself:

Stebalien commented 9 years ago

We'd probably need to prototype this in an external crate first. Doing this in a cross-platform manner will be very difficult.

Linux (the XDG spec actually) defines:

Windows defines:

I have no idea what OSX uses but to cover Windows and Linux alone, we'd need we'd probably want at least the following functions (with better names):

Even then, this wouldn't support $XDG_RUNTIME_DIR because there is no equivalent under Windows.

(I'm not saying we shouldn't try to do this, just that this is a really hard (if not impossible) problem.)

Valloric commented 9 years ago

Agreed that this should first go into an external crate to percolate for a while. After we're pretty damn sure that all the paths make sense, then move it into std.

ben0x539 commented 9 years ago

Maybe we can steal the glib design of these sort of functions since they presumably have some amount of portability nailed down.

Stebalien commented 9 years ago

@ben0x539 not really. Those methods don't distinguish between roaming versus local. Also, their user cache dir for windows is out of date; Microsoft now suggests using per-application cache directories.

SamWhited commented 7 years ago

Excluding the runtime dir, this Python module has a fairly complete list of where things should be on each platform and is useful for reference: https://github.com/ActiveState/appdirs/blob/master/appdirs.py

corngood commented 7 years ago

I was also looking for this, and came across https://docs.rs/app_dirs/. It's the best example of an existing crate that I've found so far.