Skip to content

Commit 4c056a9

Browse files
h-sigmabee-sanCopilot
authored
[Enhancement] Read config file from platform-specific config folder (#839)
* read config file from platform-specific config folder * Update src/input.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Autumn (Bee) <github@skerritt.blog> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a40c4ed commit 4c056a9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/input.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,14 @@ impl Config {
294294
///
295295
pub fn read(custom_config_path: Option<PathBuf>) -> Self {
296296
let mut content = String::new();
297-
let config_path = custom_config_path.unwrap_or_else(default_config_path);
297+
let config_path = custom_config_path.unwrap_or_else(|| {
298+
let path = default_config_path();
299+
match path.exists() {
300+
true => path,
301+
false => old_default_config_path(),
302+
}
303+
});
304+
298305
if config_path.exists() {
299306
content = match fs::read_to_string(config_path) {
300307
Ok(content) => content,
@@ -316,6 +323,15 @@ impl Config {
316323

317324
/// Constructs default path to config toml
318325
pub fn default_config_path() -> PathBuf {
326+
let Some(mut config_path) = dirs::config_dir() else {
327+
panic!("Could not infer config file path.");
328+
};
329+
config_path.push(".rustscan.toml");
330+
config_path
331+
}
332+
333+
/// Returns the deprecated home directory config path used for backwards compatibility.
334+
pub fn old_default_config_path() -> PathBuf {
319335
let Some(mut config_path) = dirs::home_dir() else {
320336
panic!("Could not infer config file path.");
321337
};

src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ The Modern Day Port Scanner."#;
219219
opts.greppable,
220220
opts.accessible
221221
);
222+
223+
if opts.config_path.is_none() {
224+
let old_config_path = input::old_default_config_path();
225+
detail!(
226+
format!(
227+
"For backwards compatibility, the config file may also be at {old_config_path:?}"
228+
),
229+
opts.greppable,
230+
opts.accessible
231+
);
232+
}
222233
}
223234

224235
#[cfg(unix)]

0 commit comments

Comments
 (0)