Only support XDG directory path configuration on Linux

This also harmonizes the server code to be consistent with Linux desktop
(with warnings printed for relative XDG paths).

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
(cherry picked from commit 06c266f231)
This commit is contained in:
Hugo Locurcio 2022-10-07 19:03:24 +02:00 committed by Rémi Verschelde
parent 5dc2a60c64
commit eb100cbddb
No known key found for this signature in database
GPG key ID: C3336907360768E1
4 changed files with 40 additions and 67 deletions

View file

@ -143,7 +143,7 @@
<method name="get_cache_dir" qualifiers="const"> <method name="get_cache_dir" qualifiers="const">
<return type="String" /> <return type="String" />
<description> <description>
Returns the [i]global[/i] cache data directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_CACHE_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_config_dir] and [method get_data_dir]. Returns the [i]global[/i] cache data directory according to the operating system's standards. On Linux, this path can be overridden by setting the [code]XDG_CACHE_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_config_dir] and [method get_data_dir].
Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path.
</description> </description>
</method> </method>
@ -171,7 +171,7 @@
<method name="get_config_dir" qualifiers="const"> <method name="get_config_dir" qualifiers="const">
<return type="String" /> <return type="String" />
<description> <description>
Returns the [i]global[/i] user configuration directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_CONFIG_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_data_dir]. Returns the [i]global[/i] user configuration directory according to the operating system's standards. On Linux, this path can be overridden by setting the [code]XDG_CONFIG_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_data_dir].
Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path.
</description> </description>
</method> </method>
@ -192,7 +192,7 @@
<method name="get_data_dir" qualifiers="const"> <method name="get_data_dir" qualifiers="const">
<return type="String" /> <return type="String" />
<description> <description>
Returns the [i]global[/i] user data directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_DATA_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_config_dir]. Returns the [i]global[/i] user data directory according to the operating system's standards. On Linux, this path can be overridden by setting the [code]XDG_DATA_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_config_dir].
Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path.
</description> </description>
</method> </method>

View file

@ -2285,14 +2285,6 @@ MainLoop *OS_OSX::get_main_loop() const {
} }
String OS_OSX::get_config_path() const { String OS_OSX::get_config_path() const {
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on macOS as well.
if (has_environment("XDG_CONFIG_HOME")) {
if (get_environment("XDG_CONFIG_HOME").is_abs_path()) {
return get_environment("XDG_CONFIG_HOME");
} else {
WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `$HOME/Library/Application Support` or `.` per the XDG Base Directory specification.");
}
}
if (has_environment("HOME")) { if (has_environment("HOME")) {
return get_environment("HOME").plus_file("Library/Application Support"); return get_environment("HOME").plus_file("Library/Application Support");
} }
@ -2300,26 +2292,10 @@ String OS_OSX::get_config_path() const {
} }
String OS_OSX::get_data_path() const { String OS_OSX::get_data_path() const {
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on macOS as well.
if (has_environment("XDG_DATA_HOME")) {
if (get_environment("XDG_DATA_HOME").is_abs_path()) {
return get_environment("XDG_DATA_HOME");
} else {
WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `get_config_path()` per the XDG Base Directory specification.");
}
}
return get_config_path(); return get_config_path();
} }
String OS_OSX::get_cache_path() const { String OS_OSX::get_cache_path() const {
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on macOS as well.
if (has_environment("XDG_CACHE_HOME")) {
if (get_environment("XDG_CACHE_HOME").is_abs_path()) {
return get_environment("XDG_CACHE_HOME");
} else {
WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `$HOME/Library/Caches` or `get_config_path()` per the XDG Base Directory specification.");
}
}
if (has_environment("HOME")) { if (has_environment("HOME")) {
return get_environment("HOME").plus_file("Library/Caches"); return get_environment("HOME").plus_file("Library/Caches");
} }

View file

@ -207,34 +207,55 @@ void OS_Server::run() {
} }
String OS_Server::get_config_path() const { String OS_Server::get_config_path() const {
#ifndef __APPLE__
if (has_environment("XDG_CONFIG_HOME")) { if (has_environment("XDG_CONFIG_HOME")) {
if (get_environment("XDG_CONFIG_HOME").is_abs_path()) {
return get_environment("XDG_CONFIG_HOME"); return get_environment("XDG_CONFIG_HOME");
} else if (has_environment("HOME")) {
return get_environment("HOME").plus_file(".config");
} else { } else {
return "."; WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.config` or `.` per the XDG Base Directory specification.");
} }
} }
#endif
if (has_environment("HOME")) {
return get_environment("HOME").plus_file(".config");
}
return ".";
}
String OS_Server::get_data_path() const { String OS_Server::get_data_path() const {
#ifndef __APPLE__
if (has_environment("XDG_DATA_HOME")) { if (has_environment("XDG_DATA_HOME")) {
if (get_environment("XDG_DATA_HOME").is_abs_path()) {
return get_environment("XDG_DATA_HOME"); return get_environment("XDG_DATA_HOME");
} else if (has_environment("HOME")) {
return get_environment("HOME").plus_file(".local/share");
} else { } else {
return get_config_path(); WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.local/share` or `get_config_path()` per the XDG Base Directory specification.");
} }
} }
#endif
if (has_environment("HOME")) {
return get_environment("HOME").plus_file(".local/share");
}
return get_config_path();
}
String OS_Server::get_cache_path() const { String OS_Server::get_cache_path() const {
#ifndef __APPLE__
if (has_environment("XDG_CACHE_HOME")) { if (has_environment("XDG_CACHE_HOME")) {
if (get_environment("XDG_CACHE_HOME").is_abs_path()) {
return get_environment("XDG_CACHE_HOME"); return get_environment("XDG_CACHE_HOME");
} else if (has_environment("HOME")) {
return get_environment("HOME").plus_file(".cache");
} else { } else {
return get_config_path(); WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.cache` or `get_config_path()` per the XDG Base Directory specification.");
} }
} }
#endif
if (has_environment("HOME")) {
return get_environment("HOME").plus_file(".cache");
}
return get_config_path();
}
String OS_Server::get_system_dir(SystemDir p_dir, bool p_shared_storage) const { String OS_Server::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
String xdgparam; String xdgparam;

View file

@ -3604,14 +3604,6 @@ uint64_t OS_Windows::get_embedded_pck_offset() const {
} }
String OS_Windows::get_config_path() const { String OS_Windows::get_config_path() const {
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well.
if (has_environment("XDG_CONFIG_HOME")) {
if (get_environment("XDG_CONFIG_HOME").is_abs_path()) {
return get_environment("XDG_CONFIG_HOME").replace("\\", "/");
} else {
WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `%APPDATA%` or `.` per the XDG Base Directory specification.");
}
}
if (has_environment("APPDATA")) { if (has_environment("APPDATA")) {
return get_environment("APPDATA").replace("\\", "/"); return get_environment("APPDATA").replace("\\", "/");
} }
@ -3619,29 +3611,13 @@ String OS_Windows::get_config_path() const {
} }
String OS_Windows::get_data_path() const { String OS_Windows::get_data_path() const {
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well.
if (has_environment("XDG_DATA_HOME")) {
if (get_environment("XDG_DATA_HOME").is_abs_path()) {
return get_environment("XDG_DATA_HOME").replace("\\", "/");
} else {
WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `get_config_path()` per the XDG Base Directory specification.");
}
}
return get_config_path(); return get_config_path();
} }
String OS_Windows::get_cache_path() const { String OS_Windows::get_cache_path() const {
static String cache_path_cache; static String cache_path_cache;
if (cache_path_cache == String()) { if (cache_path_cache == String()) {
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well. if (has_environment("LOCALAPPDATA")) {
if (has_environment("XDG_CACHE_HOME")) {
if (get_environment("XDG_CACHE_HOME").is_abs_path()) {
cache_path_cache = get_environment("XDG_CACHE_HOME").replace("\\", "/");
} else {
WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `%LOCALAPPDATA%\\cache`, `%TEMP%` or `get_config_path()` per the XDG Base Directory specification.");
}
}
if (cache_path_cache == String() && has_environment("LOCALAPPDATA")) {
cache_path_cache = get_environment("LOCALAPPDATA").replace("\\", "/"); cache_path_cache = get_environment("LOCALAPPDATA").replace("\\", "/");
} }
if (cache_path_cache == String() && has_environment("TEMP")) { if (cache_path_cache == String() && has_environment("TEMP")) {