Skip to content

Commit 0e52741

Browse files
Gabriel Alvesdavidbtadokoro
authored andcommitted
feat: relocate config.json to XDG-compliant directory
This commit changes the default location of the `config.json` configuration file for patch-hub to `~/.config/patch-hub/config.json` from its previous location at `~/.local/share/patch-hub/config.json`. This relocation ensures compliance with XDG Base Directory standards. Closes: #73 [Maintainer edits] - Remove problematic test due to nature of being unstable to suite. Signed-off-by: gabrielsrd <[email protected]> Reviewed-by: David Tadokoro <[email protected]> Signed-off-by: David Tadokoro <[email protected]>
1 parent c33c428 commit 0e52741

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/app/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl Config {
6767
}
6868

6969
let config_path = format!(
70-
"{}/.local/share/patch_hub/config.json",
70+
// "{}/.local/share/patch_hub/config.json",
71+
"{}/.config/patch-hub/config.json",
7172
env::var("HOME").unwrap()
7273
);
7374
if Path::new(&config_path).is_file() {
@@ -153,7 +154,7 @@ impl Config {
153154
path
154155
} else {
155156
format!(
156-
"{}/.local/share/patch_hub/config.json",
157+
"{}/.config/patch-hub/config.json",
157158
env::var("HOME").unwrap()
158159
)
159160
};

src/app/config/tests.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,43 @@ fn test_config_precedence() {
126126
env::remove_var("PATCH_HUB_CONFIG_PATH");
127127
env::remove_var("PATCH_HUB_PAGE_SIZE");
128128
}
129+
130+
#[test]
131+
fn test_save_patch_hub_config() {
132+
let _lock = TEST_LOCK.lock().unwrap();
133+
134+
let config = Config::build();
135+
let save_result = config.save_patch_hub_config();
136+
assert!(save_result.is_ok());
137+
138+
let config_path = format!(
139+
"{}/.config/patch-hub/config.json",
140+
env::var("HOME").unwrap()
141+
);
142+
let saved_config = std::fs::read_to_string(config_path).unwrap();
143+
let saved_config: Config = serde_json::from_str(&saved_config).unwrap();
144+
145+
assert_eq!(config.page_size(), saved_config.page_size());
146+
assert_eq!(
147+
config.patchsets_cache_dir(),
148+
saved_config.patchsets_cache_dir()
149+
);
150+
assert_eq!(
151+
config.bookmarked_patchsets_path(),
152+
saved_config.bookmarked_patchsets_path()
153+
);
154+
assert_eq!(
155+
config.mailing_lists_path(),
156+
saved_config.mailing_lists_path()
157+
);
158+
assert_eq!(
159+
config.reviewed_patchsets_path(),
160+
saved_config.reviewed_patchsets_path()
161+
);
162+
assert_eq!(config.logs_path(), saved_config.logs_path());
163+
assert_eq!(
164+
config.git_send_email_options(),
165+
saved_config.git_send_email_options()
166+
);
167+
assert_eq!(config.max_log_age(), saved_config.max_log_age());
168+
}

0 commit comments

Comments
 (0)