mirror of
https://github.com/veeso/termscp.git
synced 2026-09-27 14:31:18 -07:00
issue 150: some issues with configuration (#151)
* issue 150: some issues with configuration
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
- [Changelog](#changelog)
|
- [Changelog](#changelog)
|
||||||
|
- [0.11.1](#0111)
|
||||||
- [0.11.0](#0110)
|
- [0.11.0](#0110)
|
||||||
- [0.10.0](#0100)
|
- [0.10.0](#0100)
|
||||||
- [0.9.0](#090)
|
- [0.9.0](#090)
|
||||||
@@ -27,6 +28,14 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 0.11.1
|
||||||
|
|
||||||
|
Released on ??
|
||||||
|
|
||||||
|
- [Issue 150](https://github.com/veeso/termscp/issues/150)
|
||||||
|
- fixed config directory not being created
|
||||||
|
- before setting default ssh config path; check wheter it actually exists
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
|
|
||||||
Released on 20/02/2023
|
Released on 20/02/2023
|
||||||
|
|||||||
@@ -52,8 +52,15 @@ impl Default for RemoteConfig {
|
|||||||
let mut ssh_config_path = "~/.ssh/config".to_string();
|
let mut ssh_config_path = "~/.ssh/config".to_string();
|
||||||
ssh_config_path = ssh_config_path.replacen('~', &home_dir.to_string_lossy(), 1);
|
ssh_config_path = ssh_config_path.replacen('~', &home_dir.to_string_lossy(), 1);
|
||||||
|
|
||||||
|
// check if ssh config path exists first
|
||||||
|
let ssh_config_path = if PathBuf::from(&ssh_config_path).exists() {
|
||||||
|
Some(ssh_config_path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
ssh_config: Some(ssh_config_path),
|
ssh_config: ssh_config_path,
|
||||||
ssh_keys: HashMap::default(),
|
ssh_keys: HashMap::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -645,7 +645,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_system_config_remote_ssh_config() {
|
fn should_get_and_set_ssh_config_dir() {
|
||||||
let tmp_dir: TempDir = TempDir::new().ok().unwrap();
|
let tmp_dir: TempDir = TempDir::new().ok().unwrap();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path())
|
let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path())
|
||||||
@@ -655,7 +655,14 @@ mod tests {
|
|||||||
let home_dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from("/root"));
|
let home_dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from("/root"));
|
||||||
let mut ssh_config_path = "~/.ssh/config".to_string();
|
let mut ssh_config_path = "~/.ssh/config".to_string();
|
||||||
ssh_config_path = ssh_config_path.replacen('~', &home_dir.to_string_lossy(), 1);
|
ssh_config_path = ssh_config_path.replacen('~', &home_dir.to_string_lossy(), 1);
|
||||||
assert_eq!(client.get_ssh_config(), Some(ssh_config_path.as_str())); // Null ?
|
|
||||||
|
let ssh_config_path = if PathBuf::from(&ssh_config_path).exists() {
|
||||||
|
Some(ssh_config_path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(client.get_ssh_config(), ssh_config_path.as_deref()); // Null ?
|
||||||
client.set_ssh_config(Some(String::from("/tmp/ssh_config")));
|
client.set_ssh_config(Some(String::from("/tmp/ssh_config")));
|
||||||
assert_eq!(client.get_ssh_config(), Some("/tmp/ssh_config"));
|
assert_eq!(client.get_ssh_config(), Some("/tmp/ssh_config"));
|
||||||
client.set_ssh_config(None);
|
client.set_ssh_config(None);
|
||||||
|
|||||||
@@ -25,12 +25,13 @@ pub fn init_config_dir() -> Result<Option<PathBuf>, String> {
|
|||||||
// Append termscp dir
|
// Append termscp dir
|
||||||
p.push("termscp/");
|
p.push("termscp/");
|
||||||
// If directory doesn't exist, create it
|
// If directory doesn't exist, create it
|
||||||
match p.exists() {
|
if p.exists() {
|
||||||
true => Ok(Some(p)),
|
return Ok(Some(p));
|
||||||
false => match std::fs::create_dir(p.as_path()) {
|
}
|
||||||
Ok(_) => Ok(Some(p)),
|
// directory doesn't exist; create dir recursively
|
||||||
Err(err) => Err(err.to_string()),
|
match std::fs::create_dir_all(p.as_path()) {
|
||||||
},
|
Ok(_) => Ok(Some(p)),
|
||||||
|
Err(err) => Err(err.to_string()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|||||||
Reference in New Issue
Block a user