mirror of
https://github.com/veeso/termscp.git
synced 2025-12-06 17:15:35 -08:00
issue 150: some issues with configuration (#151)
* issue 150: some issues with configuration
This commit is contained in:
committed by
GitHub
parent
67df3dc76a
commit
1ecef6fc16
@@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
- [Changelog](#changelog)
|
||||
- [0.11.1](#0111)
|
||||
- [0.11.0](#0110)
|
||||
- [0.10.0](#0100)
|
||||
- [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
|
||||
|
||||
Released on 20/02/2023
|
||||
|
||||
@@ -52,8 +52,15 @@ impl Default for RemoteConfig {
|
||||
let mut ssh_config_path = "~/.ssh/config".to_string();
|
||||
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 {
|
||||
ssh_config: Some(ssh_config_path),
|
||||
ssh_config: ssh_config_path,
|
||||
ssh_keys: HashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,7 +645,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[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 (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())
|
||||
@@ -655,7 +655,14 @@ mod tests {
|
||||
let home_dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from("/root"));
|
||||
let mut ssh_config_path = "~/.ssh/config".to_string();
|
||||
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")));
|
||||
assert_eq!(client.get_ssh_config(), Some("/tmp/ssh_config"));
|
||||
client.set_ssh_config(None);
|
||||
|
||||
@@ -25,12 +25,13 @@ pub fn init_config_dir() -> Result<Option<PathBuf>, String> {
|
||||
// Append termscp dir
|
||||
p.push("termscp/");
|
||||
// If directory doesn't exist, create it
|
||||
match p.exists() {
|
||||
true => Ok(Some(p)),
|
||||
false => match std::fs::create_dir(p.as_path()) {
|
||||
Ok(_) => Ok(Some(p)),
|
||||
Err(err) => Err(err.to_string()),
|
||||
},
|
||||
if p.exists() {
|
||||
return Ok(Some(p));
|
||||
}
|
||||
// directory doesn't exist; create dir recursively
|
||||
match std::fs::create_dir_all(p.as_path()) {
|
||||
Ok(_) => Ok(Some(p)),
|
||||
Err(err) => Err(err.to_string()),
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
Reference in New Issue
Block a user