1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ---------------- [ File: bitcoin-argsman/src/get_setting.rs ]
crate::ix!();
impl ArgsManagerInner {
/**
| Get settings file path, or return false
| if read-write settings were disabled
| with -nosettings.
|
*/
pub fn get_settings_path(&self,
filepath: Option<&mut Box<Path>>,
temp: Option<bool>) -> bool {
let temp: bool = temp.unwrap_or(false);
if self.is_arg_negated("-settings") {
return false;
}
if filepath.is_some() {
let settings: String
= self.get_arg("-settings",BITCOIN_SETTINGS_FILENAME);
let p2 = match temp {
true => settings + ".tmp",
false => settings
}.to_string();
if let Some(filepath) = filepath {
let mut buf = PathBuf::new();
buf.push(std::fs::canonicalize(self.get_data_dir_net()).unwrap());
buf.push(std::fs::canonicalize(p2).unwrap());
*filepath = buf.into_boxed_path();
}
}
true
}
/**
| Get setting value.
|
| Result will be null if setting was unset,
| true if "-setting" argument was passed
| false if "-nosetting" argument was
| passed, and a string if a "-setting=value"
| argument was passed.
|
*/
pub fn get_setting(&self, arg: &str) -> SettingsValue {
let key = setting_name(arg);
// 1) Command-line options (last value wins, consistent with Core’s behavior).
if let Some(values) = self.settings.command_line_options().get(&key) {
if let Some(last) = values.last() {
return last.clone();
}
}
// 2) Forced settings (used by force_set_arg). Prefer last-like behavior if present.
if let Some(v) = self.settings.forced_settings().get(&key) {
return v.clone();
}
// 3) Nothing set => null
SettingsValue(UniValue::default()) // default is a null UniValue
}
/**
| Get list of setting values.
|
*/
pub fn get_settings_list(&self, arg: &str) -> Vec<SettingsValue> {
let key = setting_name(arg);
if let Some(values) = self.settings.command_line_options().get(&key) {
return values.clone();
}
if let Some(v) = self.settings.forced_settings().get(&key) {
return vec![v.clone()];
}
Vec::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn get_settings_path_respects_nosettings() {
let mut inner = ArgsManagerInner::default();
// Simulate -nosettings by setting -settings=false
inner.force_set_arg("-settings", "0");
let mut out: Option<Box<Path>> = None;
let ok = inner.get_settings_path(out.as_mut(), None);
assert!(!ok, "should return false when -nosettings is in effect");
}
}