Skip to content

Commit 6689c54

Browse files
committed
Update built-in path behavior.
We still allow override with pkg{data,config}dir, however, we don't return fcitx's path on Unix if it's not fcitx package.
1 parent d38ed42 commit 6689c54

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/lib/fcitx-utils/standardpaths_p_unix.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <optional>
1212
#include <stdexcept>
1313
#include <string>
14+
#include <string_view>
1415
#include <system_error>
1516
#include <unordered_map>
1617
#include <unordered_set>
@@ -38,7 +39,7 @@ std::optional<std::string> getEnvironmentNull(const char *env) {
3839

3940
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
4041
std::vector<std::filesystem::path> defaultPaths(
41-
StandardPathsOptions options, const char *homeEnv,
42+
StandardPathsOptions options, bool isFcitx, const char *homeEnv,
4243
const std::filesystem::path &homeFallback, const char *systemEnv = nullptr,
4344
const std::vector<std::filesystem::path> &systemFallback = {},
4445
const char *builtInPathType = nullptr,
@@ -82,7 +83,10 @@ std::vector<std::filesystem::path> defaultPaths(
8283
if (const auto *value = findValue(builtInPathMap, builtInPathType)) {
8384
builtInPaths = *value;
8485
} else {
85-
builtInPaths = {StandardPaths::fcitxPath(builtInPathType)};
86+
if (std::string_view(builtInPathType).starts_with("pkg") &&
87+
isFcitx) {
88+
builtInPaths = {StandardPaths::fcitxPath(builtInPathType)};
89+
}
8690
}
8791
for (const auto &builtInPath : builtInPaths) {
8892
const auto path = builtInPath.lexically_normal();
@@ -123,23 +127,22 @@ StandardPathsPrivate::StandardPathsPrivate(
123127
std::filesystem::path packagePath =
124128
std::u8string(packageName.begin(), packageName.end());
125129
// initialize user directory
126-
configDirs_ =
127-
defaultPaths(options_, "XDG_CONFIG_HOME", ".config", "XDG_CONFIG_DIRS",
128-
{"/etc/xdg"}, "configdir", builtInPathMap);
130+
configDirs_ = defaultPaths(options_, isFcitx, "XDG_CONFIG_HOME", ".config",
131+
"XDG_CONFIG_DIRS", {"/etc/xdg"}, "configdir",
132+
builtInPathMap);
129133
std::vector<std::filesystem::path> pkgconfigDirFallback;
130134
std::ranges::copy(
131135
configDirs_ | std::views::drop(1) |
132136
std::views::transform(
133137
[&packagePath](const auto &dir) { return dir / packagePath; }),
134138
std::back_inserter(pkgconfigDirFallback));
135139
pkgconfigDirs_ = defaultPaths(
136-
options_, (isFcitx ? "FCITX_CONFIG_HOME" : nullptr),
140+
options_, isFcitx, (isFcitx ? "FCITX_CONFIG_HOME" : nullptr),
137141
configDirs_[0] / packagePath, (isFcitx ? "FCITX_CONFIG_DIRS" : nullptr),
138-
pkgconfigDirFallback, (isFcitx ? "pkgconfigdir" : nullptr),
139-
builtInPathMap);
142+
pkgconfigDirFallback, "pkgconfigdir", builtInPathMap);
140143

141144
dataDirs_ = defaultPaths(
142-
options_, "XDG_DATA_HOME", ".local/share", "XDG_DATA_DIRS",
145+
options_, isFcitx, "XDG_DATA_HOME", ".local/share", "XDG_DATA_DIRS",
143146
{"/usr/local/share", "/usr/share"}, "datadir", builtInPathMap);
144147
std::vector<std::filesystem::path> pkgdataDirFallback;
145148
std::ranges::copy(
@@ -148,21 +151,21 @@ StandardPathsPrivate::StandardPathsPrivate(
148151
[&packagePath](const auto &dir) { return dir / packagePath; }),
149152
std::back_inserter(pkgdataDirFallback));
150153
pkgdataDirs_ = defaultPaths(
151-
options_, (isFcitx ? "FCITX_DATA_HOME" : nullptr),
154+
options_, isFcitx, (isFcitx ? "FCITX_DATA_HOME" : nullptr),
152155
dataDirs_[0] / packagePath, (isFcitx ? "FCITX_DATA_DIRS" : nullptr),
153-
pkgdataDirFallback, (isFcitx ? "pkgdatadir" : nullptr), builtInPathMap);
154-
cacheDir_ = defaultPaths(options_, "XDG_CACHE_HOME", ".cache");
156+
pkgdataDirFallback, "pkgdatadir", builtInPathMap);
157+
cacheDir_ = defaultPaths(options_, isFcitx, "XDG_CACHE_HOME", ".cache");
155158
assert(cacheDir_.size() == 1);
156159
std::error_code ec;
157160
auto tmpdir = std::filesystem::temp_directory_path(ec);
158161
runtimeDir_ =
159-
defaultPaths(options_, "XDG_RUNTIME_DIR",
162+
defaultPaths(options_, isFcitx, "XDG_RUNTIME_DIR",
160163
tmpdir.empty() ? std::filesystem::path("/tmp") : tmpdir);
161164
assert(runtimeDir_.size() == 1);
162-
// Though theoratically, this is also fcitxPath, we just simply don't
165+
// Though theoretically, this is also fcitxPath, we just simply don't
163166
// use it here.
164167
addonDirs_ =
165-
defaultPaths(options_, nullptr, {}, "FCITX_ADDON_DIRS",
168+
defaultPaths(options_, isFcitx, nullptr, {}, "FCITX_ADDON_DIRS",
166169
{FCITX_INSTALL_ADDONDIR}, "addondir", builtInPathMap);
167170

168171
syncUmask();

0 commit comments

Comments
 (0)