Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit eb77fea

Browse files
committed
Revert "Enhancement: Use XDG Directory Specification by default on Linux (#2035)"
This reverts commit 0151617.
1 parent 57004f5 commit eb77fea

File tree

2 files changed

+3
-50
lines changed

2 files changed

+3
-50
lines changed

engine/e2e-test/cli/common/test_create_log_folder.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@
66
from utils.test_runner import start_server, stop_server
77

88

9-
def get_root_path():
10-
if platform.system() == "Linux":
11-
# For Linux, use the XDG base directory.
12-
# Here we use XDG_DATA_HOME if set, otherwise default to ~/.local/share.
13-
return Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share"))
14-
else:
15-
return Path.home()
16-
179
class TestCreateLogFolder:
1810
@pytest.fixture(autouse=True)
1911
def setup_and_teardown(self):
2012
# Setup
2113
stop_server()
22-
root = get_root_path()
14+
root = Path.home()
2315
if os.path.exists(root / "cortexcpp" / "logs"):
2416
shutil.rmtree(root / "cortexcpp" / "logs")
2517
success = start_server()
@@ -32,7 +24,7 @@ def setup_and_teardown(self):
3224
stop_server()
3325

3426
def test_create_log_folder_run_successfully(self):
35-
root = get_root_path()
27+
root = Path.home()
3628
assert (
3729
os.path.exists(root / "cortexcpp" / "logs")
3830
or os.path.exists(root / "cortexcpp-beta" / "logs")

engine/utils/file_manager_utils.cc

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ std::filesystem::path GetHomeDirectoryPath() {
7878
return std::filesystem::path(homeDir);
7979
}
8080

81-
// Helper function to get XDG base directory, falling back to default if not set
82-
std::filesystem::path GetXDGDirectoryPath(const std::string& envVar,
83-
const std::string& defaultPath) {
84-
if (const char* envValue = std::getenv(envVar.c_str());
85-
envValue && std::strlen(envValue) > 0) {
86-
return std::filesystem::path(envValue);
87-
}
88-
return GetHomeDirectoryPath() / defaultPath;
89-
}
90-
9181
std::filesystem::path GetConfigurationPath() {
9282
#ifndef CORTEX_CONFIG_FILE_PATH
9383
#define CORTEX_CONFIG_FILE_PATH kDefaultConfigurationPath
@@ -123,14 +113,9 @@ std::filesystem::path GetConfigurationPath() {
123113
std::string config_file_name{kCortexConfigurationFileName};
124114
config_file_name.append(env_postfix);
125115
// CTL_INF("Config file name: " + config_file_name);
126-
#if defined(__linux__)
127-
auto config_base_path =
128-
GetXDGDirectoryPath("XDG_CONFIG_HOME", ".config") / kCortexFolderName;
129-
auto configuration_path = config_base_path / config_file_name;
130-
#else
116+
131117
auto home_path = GetHomeDirectoryPath();
132118
auto configuration_path = home_path / config_file_name;
133-
#endif
134119
return configuration_path;
135120
}
136121

@@ -165,20 +150,11 @@ cpp::result<void, std::string> UpdateCortexConfig(
165150
config_yaml_utils::CortexConfig GetDefaultConfig() {
166151
auto config_path = GetConfigurationPath();
167152
auto default_data_folder_name = GetDefaultDataFolderName();
168-
#if defined(__linux__)
169-
auto default_data_folder_path =
170-
cortex_data_folder_path.empty()
171-
? file_manager_utils::GetXDGDirectoryPath("XDG_DATA_HOME",
172-
".local/share") /
173-
default_data_folder_name
174-
: std::filesystem::path(cortex_data_folder_path);
175-
#else
176153
auto default_data_folder_path =
177154
cortex_data_folder_path.empty()
178155
? file_manager_utils::GetHomeDirectoryPath() /
179156
default_data_folder_name
180157
: std::filesystem::path(cortex_data_folder_path);
181-
#endif
182158

183159
return config_yaml_utils::CortexConfig{
184160
#if defined(_WIN32)
@@ -228,10 +204,6 @@ cpp::result<void, std::string> CreateConfigFileIfNotExist() {
228204
// already exists, no need to create
229205
return {};
230206
}
231-
if (!std::filesystem::exists(config_path.parent_path())) {
232-
// Ensure the configuration directory exists
233-
std::filesystem::create_directories(config_path.parent_path());
234-
}
235207

236208
CLI_LOG("Config file not found. Creating one at " + config_path.string());
237209
auto config = GetDefaultConfig();
@@ -264,13 +236,8 @@ std::filesystem::path GetCortexDataPath() {
264236
data_folder_path = std::filesystem::path(config.dataFolderPath);
265237
#endif
266238
} else {
267-
#if defined(__linux__)
268-
auto data_base_path = GetXDGDirectoryPath("XDG_DATA_HOME", ".local/share");
269-
data_folder_path = data_base_path / GetDefaultDataFolderName();
270-
#else
271239
auto home_path = GetHomeDirectoryPath();
272240
data_folder_path = home_path / kCortexFolderName;
273-
#endif
274241
}
275242

276243
if (!std::filesystem::exists(data_folder_path)) {
@@ -286,19 +253,13 @@ std::filesystem::path GetCortexLogPath() {
286253
// TODO: get the variant of cortex. As discussed, we will have: prod, beta, nightly
287254

288255
// currently we will store cortex data at ~/cortexcpp
289-
// On linux, we follow the xdg directory specification
290256
auto config = GetCortexConfig();
291257
std::filesystem::path log_folder_path;
292258
if (!config.logFolderPath.empty()) {
293259
log_folder_path = std::filesystem::path(config.logFolderPath);
294260
} else {
295-
#if defined(__linux__)
296-
auto data_base_path = GetXDGDirectoryPath("XDG_DATA_HOME", ".local/share");
297-
log_folder_path = data_base_path / GetDefaultDataFolderName() / "logs";
298-
#else
299261
auto home_path = GetHomeDirectoryPath();
300262
log_folder_path = home_path / kCortexFolderName;
301-
#endif
302263
}
303264

304265
if (!std::filesystem::exists(log_folder_path)) {

0 commit comments

Comments
 (0)