11
11
#include < optional>
12
12
#include < stdexcept>
13
13
#include < string>
14
+ #include < string_view>
14
15
#include < system_error>
15
16
#include < unordered_map>
16
17
#include < unordered_set>
@@ -38,7 +39,7 @@ std::optional<std::string> getEnvironmentNull(const char *env) {
38
39
39
40
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
40
41
std::vector<std::filesystem::path> defaultPaths (
41
- StandardPathsOptions options, const char *homeEnv,
42
+ StandardPathsOptions options, bool isFcitx, const char *homeEnv,
42
43
const std::filesystem::path &homeFallback, const char *systemEnv = nullptr ,
43
44
const std::vector<std::filesystem::path> &systemFallback = {},
44
45
const char *builtInPathType = nullptr ,
@@ -82,7 +83,10 @@ std::vector<std::filesystem::path> defaultPaths(
82
83
if (const auto *value = findValue (builtInPathMap, builtInPathType)) {
83
84
builtInPaths = *value;
84
85
} else {
85
- builtInPaths = {StandardPaths::fcitxPath (builtInPathType)};
86
+ if (std::string_view (builtInPathType).starts_with (" pkg" ) &&
87
+ isFcitx) {
88
+ builtInPaths = {StandardPaths::fcitxPath (builtInPathType)};
89
+ }
86
90
}
87
91
for (const auto &builtInPath : builtInPaths) {
88
92
const auto path = builtInPath.lexically_normal ();
@@ -123,23 +127,22 @@ StandardPathsPrivate::StandardPathsPrivate(
123
127
std::filesystem::path packagePath =
124
128
std::u8string (packageName.begin (), packageName.end ());
125
129
// 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);
129
133
std::vector<std::filesystem::path> pkgconfigDirFallback;
130
134
std::ranges::copy (
131
135
configDirs_ | std::views::drop (1 ) |
132
136
std::views::transform (
133
137
[&packagePath](const auto &dir) { return dir / packagePath; }),
134
138
std::back_inserter (pkgconfigDirFallback));
135
139
pkgconfigDirs_ = defaultPaths (
136
- options_, (isFcitx ? " FCITX_CONFIG_HOME" : nullptr ),
140
+ options_, isFcitx, (isFcitx ? " FCITX_CONFIG_HOME" : nullptr ),
137
141
configDirs_[0 ] / packagePath, (isFcitx ? " FCITX_CONFIG_DIRS" : nullptr ),
138
- pkgconfigDirFallback, (isFcitx ? " pkgconfigdir" : nullptr ),
139
- builtInPathMap);
142
+ pkgconfigDirFallback, " pkgconfigdir" , builtInPathMap);
140
143
141
144
dataDirs_ = defaultPaths (
142
- options_, " XDG_DATA_HOME" , " .local/share" , " XDG_DATA_DIRS" ,
145
+ options_, isFcitx, " XDG_DATA_HOME" , " .local/share" , " XDG_DATA_DIRS" ,
143
146
{" /usr/local/share" , " /usr/share" }, " datadir" , builtInPathMap);
144
147
std::vector<std::filesystem::path> pkgdataDirFallback;
145
148
std::ranges::copy (
@@ -148,21 +151,21 @@ StandardPathsPrivate::StandardPathsPrivate(
148
151
[&packagePath](const auto &dir) { return dir / packagePath; }),
149
152
std::back_inserter (pkgdataDirFallback));
150
153
pkgdataDirs_ = defaultPaths (
151
- options_, (isFcitx ? " FCITX_DATA_HOME" : nullptr ),
154
+ options_, isFcitx, (isFcitx ? " FCITX_DATA_HOME" : nullptr ),
152
155
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" );
155
158
assert (cacheDir_.size () == 1 );
156
159
std::error_code ec;
157
160
auto tmpdir = std::filesystem::temp_directory_path (ec);
158
161
runtimeDir_ =
159
- defaultPaths (options_, " XDG_RUNTIME_DIR" ,
162
+ defaultPaths (options_, isFcitx, " XDG_RUNTIME_DIR" ,
160
163
tmpdir.empty () ? std::filesystem::path (" /tmp" ) : tmpdir);
161
164
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
163
166
// use it here.
164
167
addonDirs_ =
165
- defaultPaths (options_, nullptr , {}, " FCITX_ADDON_DIRS" ,
168
+ defaultPaths (options_, isFcitx, nullptr , {}, " FCITX_ADDON_DIRS" ,
166
169
{FCITX_INSTALL_ADDONDIR}, " addondir" , builtInPathMap);
167
170
168
171
syncUmask ();
0 commit comments