mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
get_bookmarks_paths; get_config_paths
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
extern crate dirs;
|
extern crate dirs;
|
||||||
|
|
||||||
// Ext
|
// Ext
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
/// ### get_config_dir
|
/// ### get_config_dir
|
||||||
///
|
///
|
||||||
@@ -56,6 +56,32 @@ pub fn init_config_dir() -> Result<Option<PathBuf>, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### get_bookmarks_paths
|
||||||
|
///
|
||||||
|
/// Get paths for bookmarks client
|
||||||
|
/// Returns: path of bookmarks.toml and path of key
|
||||||
|
pub fn get_bookmarks_paths(config_dir: &Path) -> (PathBuf, PathBuf) {
|
||||||
|
// Prepare paths
|
||||||
|
let mut bookmarks_file: PathBuf = PathBuf::from(config_dir);
|
||||||
|
bookmarks_file.push("bookmarks.toml");
|
||||||
|
let mut key_file: PathBuf = PathBuf::from(config_dir);
|
||||||
|
key_file.push(".bookmarks.key"); // key file is hidden
|
||||||
|
(bookmarks_file, key_file)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ### get_config_paths
|
||||||
|
///
|
||||||
|
/// Returns paths for config client
|
||||||
|
/// Returns: path of config.toml and path for ssh keys
|
||||||
|
pub fn get_config_paths(config_dir: &Path) -> (PathBuf, PathBuf) {
|
||||||
|
// Prepare paths
|
||||||
|
let mut bookmarks_file: PathBuf = PathBuf::from(config_dir);
|
||||||
|
bookmarks_file.push("config.toml");
|
||||||
|
let mut keys_dir: PathBuf = PathBuf::from(config_dir);
|
||||||
|
keys_dir.push(".ssh/"); // Path where keys are stored
|
||||||
|
(bookmarks_file, keys_dir)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@@ -92,4 +118,26 @@ mod tests {
|
|||||||
// Remove file
|
// Remove file
|
||||||
assert!(std::fs::remove_file(conf_dir.as_path()).is_ok());
|
assert!(std::fs::remove_file(conf_dir.as_path()).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_system_environment_get_bookmarks_paths() {
|
||||||
|
assert_eq!(
|
||||||
|
get_bookmarks_paths(&Path::new("/home/omar/.config/termscp/")),
|
||||||
|
(
|
||||||
|
PathBuf::from("/home/omar/.config/termscp/bookmarks.toml"),
|
||||||
|
PathBuf::from("/home/omar/.config/termscp/.bookmarks.key")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_system_environment_get_config_paths() {
|
||||||
|
assert_eq!(
|
||||||
|
get_config_paths(&Path::new("/home/omar/.config/termscp/")),
|
||||||
|
(
|
||||||
|
PathBuf::from("/home/omar/.config/termscp/config.toml"),
|
||||||
|
PathBuf::from("/home/omar/.config/termscp/.ssh/")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,12 +225,8 @@ impl AuthActivity {
|
|||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
// If some configure client, otherwise do nothing; don't bother users telling them that bookmarks are not supported on their system.
|
// If some configure client, otherwise do nothing; don't bother users telling them that bookmarks are not supported on their system.
|
||||||
if let Some(path) = path {
|
if let Some(path) = path {
|
||||||
// Prepare paths
|
let (bookmarks_file, key_file): (PathBuf, PathBuf) = environment::get_bookmarks_paths(path.as_path());
|
||||||
let mut bookmarks_file: PathBuf = path.clone();
|
// Initialize client
|
||||||
bookmarks_file.push("bookmarks.toml");
|
|
||||||
let mut key_file: PathBuf = path;
|
|
||||||
key_file.push(".bookmarks.key"); // key file is hidden
|
|
||||||
// Initialize client
|
|
||||||
match BookmarksClient::new(bookmarks_file.as_path(), key_file.as_path(), 16) {
|
match BookmarksClient::new(bookmarks_file.as_path(), key_file.as_path(), 16) {
|
||||||
Ok(cli) => self.bookmarks_client = Some(cli),
|
Ok(cli) => self.bookmarks_client = Some(cli),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user