Skip to content

Commit

Permalink
Do not use FCITX_* env to set standard path if it's not fcitx.
Browse files Browse the repository at this point in the history
In fcitx we have FCITX_* to override fcitx specific path. This should
not be used for non-fcitx package name.
  • Loading branch information
wengxt committed Apr 21, 2024
1 parent 9d12781 commit aafc5b5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/lib/fcitx-utils/standardpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ class StandardPathPrivate {
const std::unordered_map<std::string, std::string> &builtInPathMap,
bool skipBuiltInPath, bool skipUserPath)
: skipBuiltInPath_(skipBuiltInPath), skipUserPath_(skipUserPath) {
bool isFcitx = (packageName == "fcitx5");
// initialize user directory
configHome_ = defaultPath("XDG_CONFIG_HOME", ".config");
pkgconfigHome_ =
defaultPath("FCITX_CONFIG_HOME",
defaultPath((isFcitx ? "FCITX_CONFIG_HOME" : nullptr),
constructPath(configHome_, packageName).c_str());
configDirs_ = defaultPaths("XDG_CONFIG_DIRS", "/etc/xdg",
builtInPathMap, nullptr);
Expand All @@ -93,13 +94,14 @@ class StandardPathPrivate {
path = constructPath(path, packageName);
}
pkgconfigDirs_ =
defaultPaths("FCITX_CONFIG_DIRS",
defaultPaths((isFcitx ? "FCITX_CONFIG_DIRS" : nullptr),
stringutils::join(pkgconfigDirFallback, ":").c_str(),
builtInPathMap, nullptr);

dataHome_ = defaultPath("XDG_DATA_HOME", ".local/share");
pkgdataHome_ = defaultPath(
"FCITX_DATA_HOME", constructPath(dataHome_, packageName).c_str());
pkgdataHome_ =
defaultPath((isFcitx ? "FCITX_DATA_HOME" : nullptr),
constructPath(dataHome_, packageName).c_str());
dataDirs_ = defaultPaths("XDG_DATA_DIRS", "/usr/local/share:/usr/share",
builtInPathMap,
skipBuiltInPath_ ? nullptr : "datadir");
Expand All @@ -108,7 +110,7 @@ class StandardPathPrivate {
path = constructPath(path, packageName);
}
pkgdataDirs_ = defaultPaths(
"FCITX_DATA_DIRS",
(isFcitx ? "FCITX_DATA_DIRS" : nullptr),
stringutils::join(pkgdataDirFallback, ":").c_str(), builtInPathMap,
skipBuiltInPath_ ? nullptr : "pkgdatadir");
cacheHome_ = defaultPath("XDG_CACHE_HOME", ".cache");
Expand Down Expand Up @@ -179,7 +181,10 @@ class StandardPathPrivate {
private:
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
static std::string defaultPath(const char *env, const char *defaultPath) {
char *cdir = getenv(env);
char *cdir = nullptr;
if (env) {
cdir = getenv(env);
}
std::string dir;
if (cdir && cdir[0]) {
dir = cdir;
Expand Down Expand Up @@ -223,7 +228,10 @@ class StandardPathPrivate {
const char *builtInPathType) {
std::vector<std::string> dirs;

const char *dir = getenv(env);
const char *dir = nullptr;
if (env) {
dir = getenv(env);
}
if (!dir) {
dir = defaultPath;
}
Expand Down

0 comments on commit aafc5b5

Please sign in to comment.