use XDG paths

'pref-dir = ${XDG_CONFIG_HOME:-~/.config}/racket/
 'pref-file = (build-path (find-system-path 'pref-dir) "racket-prefs.rktd")
 'addon-dir = ${XDG_DATA_HOME:-~/.local/share}/racket/
 'init-dir = ${XDG_CONFIG_HOME:-~/.config}/racket/
 'init-file = (build-path (find-system-path 'init-dir) "racketrc.rktl")
 'cache-dir = ${XDG_CACHE_HOME:-~/.cache}/racket/

... except actually the "~" uses PLTUSERHOME if set.

Use cache-dir as default "download-cache" parent dir.

related to #2740
This commit is contained in:
Ryan Culpepper 2020-08-28 04:34:02 -06:00 committed by Matthew Flatt
parent 979fbf551d
commit f52bff8a31
8 changed files with 94 additions and 21 deletions

View File

@ -161,8 +161,8 @@ directory}:
@item{@indexed-racket['download-cache-dir] --- a path string used as
the location for storing downloaded package archives. When not
specified, packages are cached in a @filepath{download-cache}
directory in the user's add-on directory as reported by
@racket[(find-system-path 'addon-dir)].}
directory in the user's cache directory as reported by
@racket[(find-system-path 'cache-dir)].}
@item{@indexed-racket['download-cache-max-files] and
@indexed-racket['download-cache-max-bytes] --- real numbers that

View File

@ -52,8 +52,11 @@ by @racket[kind], which must be one of the following:
the current executable is used as the home directory.}
@item{@indexed-racket['pref-dir] --- the standard directory for
storing the current user's preferences. On Unix, the directory is
@filepath{.racket} in the @tech{user's home directory}. On Windows,
storing the current user's preferences. On Unix, the directory is the
@filepath{racket} subdirectory of the path specified by
@indexed-envvar{XDG_CONFIG_HOME}, or @filepath{.config/racket} in the
@tech{user's home directory} if @envvar{XDG_CONFIG_HOME} is not set to
an absolute path. On Windows,
it is @filepath{Racket} in the @tech{user's home directory} if
determined by @envvar{PLTUSERHOME}, otherwise in the user's
application-data folder as specified by the Windows registry; the
@ -79,8 +82,9 @@ by @racket[kind], which must be one of the following:
if it is defined, otherwise it is the current directory.}
@item{@indexed-racket['init-dir] --- the directory containing the
initialization file used by the Racket executable.
It is the same as the @tech{user's home directory}.}
initialization file used by the Racket executable. On Unix, it is
the same as the result returned for @racket['pref-dir]; on Mac OS and
Windows, it is the same as the @tech{user's home directory}.}
@item{@indexed-racket['init-file] --- the file loaded at start-up by
the Racket executable. The directory part of the
@ -89,9 +93,9 @@ by @racket[kind], which must be one of the following:
@itemize[
@item{@|AllUnix|: @indexed-file{.racketrc}}
@item{Unix and Windows: @indexed-file{racketrc.rktl}}
@item{Windows: @indexed-file{racketrc.rktl}}
@item{Mac OS: @indexed-file{.racketrc}}
]}
@ -121,8 +125,19 @@ by @racket[kind], which must be one of the following:
environment variable or flag is specified, or if the value is not a
legal path name, then this directory defaults to
@filepath{Library/Racket} in the @tech{user's home directory} on Mac
OS and @racket['pref-dir] otherwise. The directory might not
exist.}
OS and @racket['pref-dir] on Windows. On Unix, it is the
@filepath{racket} subdirectory of the path specified by
@indexed-envvar{XDG_DATA_HOME}, or @filepath{.local/share/racket} in
the @tech{user's home directory} if @envvar{XDG_CONFIG_HOME} is not
set to an absolute path. The directory might not exist.}
@item{@indexed-racket['cache-dir] --- a directory for storing
user-specific caches. On Unix, it is the @filepath{racket}
subdirectory of the path specified by @indexed-envvar{XDG_CACHE_HOME},
or @filepath{.cache/racket} in the @tech{user's home directory} if
@envvar{XDG_CACHE_HOME} is not set to an absolute path. On Mac OS and
Windows, it is the same as the result returned for @racket['addon-dir].
The directory might not exists.}
@item{@indexed-racket['doc-dir] --- the standard directory for
storing the current user's documents. On Unix, it's

View File

@ -69,7 +69,7 @@
"https://planet-compats.racket-lang.org")]
['default-scope "user"]
['installation-name (version)]
['download-cache-dir (build-path (find-system-path 'addon-dir)
['download-cache-dir (build-path (find-system-path 'cache-dir)
"download-cache")]
['download-cache-max-files 1024]
['download-cache-max-bytes (* 64 1024 1024)]

View File

@ -123,7 +123,7 @@ READ_ONLY static Scheme_Object *doc_dir_symbol, *desk_dir_symbol;
READ_ONLY static Scheme_Object *init_dir_symbol, *init_file_symbol, *sys_dir_symbol;
READ_ONLY static Scheme_Object *exec_file_symbol, *run_file_symbol, *collects_dir_symbol;
READ_ONLY static Scheme_Object *pref_file_symbol, *orig_dir_symbol, *addon_dir_symbol;
READ_ONLY static Scheme_Object *config_dir_symbol;
READ_ONLY static Scheme_Object *config_dir_symbol, *cache_dir_symbol;
READ_ONLY static Scheme_Object *host_collects_dir_symbol, *host_config_dir_symbol;
SHARED_OK static Scheme_Object *exec_cmd;
@ -165,6 +165,7 @@ void scheme_init_file(Scheme_Startup_Env *env)
REGISTER_SO(host_config_dir_symbol);
REGISTER_SO(orig_dir_symbol);
REGISTER_SO(addon_dir_symbol);
REGISTER_SO(cache_dir_symbol);
REGISTER_SO(windows_symbol);
REGISTER_SO(unix_symbol);
@ -199,6 +200,7 @@ void scheme_init_file(Scheme_Startup_Env *env)
host_config_dir_symbol = scheme_intern_symbol("host-config-dir");
orig_dir_symbol = scheme_intern_symbol("orig-dir");
addon_dir_symbol = scheme_intern_symbol("addon-dir");
cache_dir_symbol = scheme_intern_symbol("cache-dir");
windows_symbol = scheme_intern_symbol("windows");
unix_symbol = scheme_intern_symbol("unix");
@ -5022,10 +5024,12 @@ find_system_path(int argc, Scheme_Object **argv)
} else if (argv[0] == addon_dir_symbol) {
if (addon_dir) return addon_dir;
which = RKTIO_PATH_ADDON_DIR;
} else if (argv[0] == cache_dir_symbol) {
which = RKTIO_PATH_CACHE_DIR;
} else {
scheme_wrong_contract("find-system-path",
"(or/c 'home-dir 'pref-dir 'pref-file 'temp-dir\n"
" 'init-dir 'init-file 'addon-dir\n"
" 'init-dir 'init-file 'addon-dir 'cache-dir\n"
" 'doc-dir 'desk-dir 'sys-dir 'exec-file 'run-file\n"
" 'collects-dir 'config-dir 'orig-dir\n"
" 'host-collects-dir 'host-config-dir)",

View File

@ -47,6 +47,7 @@
[(pref-file) (rktio-system-path who RKTIO_PATH_PREF_FILE)]
[(addon-dir) (as-dir (or addon-dir
(rktio-system-path who RKTIO_PATH_ADDON_DIR)))]
[(cache-dir) (as-dir (rktio-system-path who RKTIO_PATH_CACHE_DIR))]
[(home-dir) (as-dir (rktio-system-path who RKTIO_PATH_HOME_DIR))]
[(desk-dir) (as-dir (rktio-system-path who RKTIO_PATH_DESK_DIR))]
[(doc-dir) (as-dir (rktio-system-path who RKTIO_PATH_DOC_DIR))]
@ -55,7 +56,7 @@
[else (raise-argument-error who
(string-append
"(or/c 'home-dir 'pref-dir 'pref-file 'temp-dir\n"
" 'init-dir 'init-file 'addon-dir\n"
" 'init-dir 'init-file 'addon-dir 'cache-dir\n"
" 'doc-dir 'desk-dir 'sys-dir 'exec-file 'run-file\n"
" 'collects-dir 'config-dir 'orig-dir\n"
" 'host-collects-dir 'host-config-dir)")

View File

@ -963,7 +963,8 @@ enum {
RKTIO_PATH_DESK_DIR,
RKTIO_PATH_DOC_DIR,
RKTIO_PATH_INIT_DIR,
RKTIO_PATH_INIT_FILE
RKTIO_PATH_INIT_FILE,
RKTIO_PATH_CACHE_DIR
};
RKTIO_EXTERN char *rktio_expand_user_tilde(rktio_t *rktio, rktio_const_string_t filename);

View File

@ -89,6 +89,7 @@
(define-constant RKTIO_PATH_DOC_DIR 7)
(define-constant RKTIO_PATH_INIT_DIR 8)
(define-constant RKTIO_PATH_INIT_FILE 9)
(define-constant RKTIO_PATH_CACHE_DIR 10)
(define-constant RKTIO_OS_SIGNAL_NONE -1)
(define-constant RKTIO_OS_SIGNAL_INT 0)
(define-constant RKTIO_OS_SIGNAL_TERM 1)

View File

@ -1943,20 +1943,61 @@ char *rktio_system_path(rktio_t *rktio, int which)
return rktio_get_current_directory(rktio);
}
#define USE_XDG_BASEDIR 1
{
/* Everything else is in ~: */
char *home_str, *alt_home, *home;
if ((which == RKTIO_PATH_PREF_DIR)
|| (which == RKTIO_PATH_PREF_FILE)
|| (which == RKTIO_PATH_ADDON_DIR)) {
|| (which == RKTIO_PATH_PREF_FILE)
|| (which == RKTIO_PATH_ADDON_DIR)
|| (which == RKTIO_PATH_CACHE_DIR)
|| (which == RKTIO_PATH_INIT_DIR)
|| (which == RKTIO_PATH_INIT_FILE)) {
#if defined(OS_X) && !defined(XONX)
if (which == RKTIO_PATH_ADDON_DIR)
if ((which == RKTIO_PATH_ADDON_DIR)
|| (which == RKTIO_PATH_CACHE_DIR))
home_str = "~/Library/Racket/";
else if ((which == RKTIO_PATH_INIT_DIR)
|| (which == RKTIO_PATH_INIT_FILE))
home_str = "~/";
else
home_str = "~/Library/Preferences/";
#elif USE_XDG_BASEDIR
char *envvar, *xdg_dir, *suffix;
if (which == RKTIO_PATH_ADDON_DIR) {
home_str = "~/.local/share/racket/";
envvar = "XDG_DATA_HOME";
suffix = "racket/";
} else if (which == RKTIO_PATH_CACHE_DIR) {
home_str = "~/.cache/racket/";
envvar = "XDG_CACHE_HOME";
suffix = "racket/";
} else {
home_str = "~/.config/racket/";
envvar = "XDG_CONFIG_HOME";
if ((which == RKTIO_PATH_PREF_DIR)
|| (which == RKTIO_PATH_INIT_DIR)) {
suffix = "racket/";
} else if (which == RKTIO_PATH_PREF_FILE) {
suffix = "racket/racket-prefs.rktd";
} else { /* (which == RKTIO_PATH_INIT_FILE) */
suffix = "racket/racketrc.rktl";
}
}
xdg_dir = rktio_getenv(rktio, envvar);
/* xdg_dir is invalid if it is not an absolute path */
if (xdg_dir && (strlen(xdg_dir) > 0) && (xdg_dir[0] == '/')) {
return append_paths(xdg_dir, suffix, 1, 0);
} else {
free(xdg_dir);
}
#else
home_str = "~/.racket/";
if ((which == RKTIO_PATH_INIT_DIR) || (which == RKTIO_INIT_FILE)) {
home_str = "~/";
} else { /* RKTIO_PATH_{ADDON_DIR,PREF_DIR,PREF_FILE} */
home_str = "~/.racket/";
}
#endif
} else {
#if defined(OS_X) && !defined(XONX)
@ -1985,11 +2026,19 @@ char *rktio_system_path(rktio_t *rktio, int which)
if ((which == RKTIO_PATH_PREF_DIR) || (which == RKTIO_PATH_INIT_DIR)
|| (which == RKTIO_PATH_HOME_DIR) || (which == RKTIO_PATH_ADDON_DIR)
|| (which == RKTIO_PATH_DESK_DIR) || (which == RKTIO_PATH_DOC_DIR))
|| (which == RKTIO_PATH_DESK_DIR) || (which == RKTIO_PATH_DOC_DIR)
|| (which == RKTIO_PATH_CACHE_DIR))
return home;
if (which == RKTIO_PATH_INIT_FILE)
if (which == RKTIO_PATH_INIT_FILE) {
#if defined(OS_X) && !defined(XONX)
return append_paths(home, ".racketrc", 1, 0);
#elif USE_XDG_BASEDIR
return append_paths(home, "racketrc.rktl", 1, 0);
#else
return append_paths(home, ".racketrc", 1, 0);
#endif
}
if (which == RKTIO_PATH_PREF_FILE) {
#if defined(OS_X) && !defined(XONX)
return append_paths(home, "org.racket-lang.prefs.rktd", 1, 0);
@ -2041,6 +2090,7 @@ char *rktio_system_path(rktio_t *rktio, int which)
int which_folder;
if ((which == RKTIO_PATH_ADDON_DIR)
|| (which == RKTIO_PATH_CACHE_DIR) /* maybe CSIDL_LOCAL_APPDATA instead? */
|| (which == RKTIO_PATH_PREF_DIR)
|| (which == RKTIO_PATH_PREF_FILE))
which_folder = CSIDL_APPDATA;
@ -2134,6 +2184,7 @@ char *rktio_system_path(rktio_t *rktio, int which)
return home;
if ((which == RKTIO_PATH_ADDON_DIR)
|| (which == RKTIO_PATH_CACHE_DIR)
|| (which == RKTIO_PATH_PREF_DIR)
|| (which == RKTIO_PATH_PREF_FILE)) {
home = append_paths(home, "Racket", 1, 0);