mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
save local file paths in bookmark (#204)
* fix: renamed Bookmark 'directory' to 'remote_path' (keep name in file) * feat: local_path as file transfer parameter and in bookmark
This commit is contained in:
committed by
GitHub
parent
ee28d34f29
commit
ca005cbecd
@@ -38,8 +38,11 @@ pub struct Bookmark {
|
||||
pub username: Option<String>,
|
||||
/// Password is optional; base64, aes-128 encrypted password
|
||||
pub password: Option<String>,
|
||||
/// Remote folder to connect to
|
||||
pub directory: Option<PathBuf>,
|
||||
/// Remote folder to connect to (serde rename for legacy reasons)
|
||||
#[serde(rename = "directory")]
|
||||
pub remote_path: Option<PathBuf>,
|
||||
/// local folder to open at startup
|
||||
pub local_path: Option<PathBuf>,
|
||||
/// S3 params; optional. When used other fields are empty for sure
|
||||
pub s3: Option<S3Params>,
|
||||
/// SMB params; optional. Extra params required for SMB protocol
|
||||
@@ -71,7 +74,8 @@ pub struct SmbParams {
|
||||
impl From<FileTransferParams> for Bookmark {
|
||||
fn from(params: FileTransferParams) -> Self {
|
||||
let protocol = params.protocol;
|
||||
let directory = params.entry_directory;
|
||||
let remote_path = params.remote_path;
|
||||
let local_path = params.local_path;
|
||||
// Create generic or others
|
||||
match params.params {
|
||||
ProtocolParams::Generic(params) => Self {
|
||||
@@ -80,7 +84,8 @@ impl From<FileTransferParams> for Bookmark {
|
||||
port: Some(params.port),
|
||||
username: params.username,
|
||||
password: params.password,
|
||||
directory,
|
||||
remote_path,
|
||||
local_path,
|
||||
s3: None,
|
||||
smb: None,
|
||||
},
|
||||
@@ -90,7 +95,8 @@ impl From<FileTransferParams> for Bookmark {
|
||||
port: None,
|
||||
username: None,
|
||||
password: None,
|
||||
directory,
|
||||
remote_path,
|
||||
local_path,
|
||||
s3: Some(S3Params::from(params)),
|
||||
smb: None,
|
||||
},
|
||||
@@ -104,7 +110,8 @@ impl From<FileTransferParams> for Bookmark {
|
||||
port: None,
|
||||
username: params.username,
|
||||
password: params.password,
|
||||
directory,
|
||||
remote_path,
|
||||
local_path,
|
||||
s3: None,
|
||||
},
|
||||
}
|
||||
@@ -155,7 +162,8 @@ impl From<Bookmark> for FileTransferParams {
|
||||
Self::new(bookmark.protocol, ProtocolParams::Smb(params))
|
||||
}
|
||||
}
|
||||
.entry_directory(bookmark.directory) // Set entry directory
|
||||
.remote_path(bookmark.remote_path) // Set entry remote_path
|
||||
.local_path(bookmark.local_path) // Set entry local path
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +254,8 @@ mod tests {
|
||||
protocol: FileTransferProtocol::Sftp,
|
||||
username: Some(String::from("root")),
|
||||
password: Some(String::from("password")),
|
||||
directory: Some(PathBuf::from("/tmp")),
|
||||
remote_path: Some(PathBuf::from("/tmp")),
|
||||
local_path: Some(PathBuf::from("/usr")),
|
||||
s3: None,
|
||||
smb: None,
|
||||
};
|
||||
@@ -256,7 +265,8 @@ mod tests {
|
||||
protocol: FileTransferProtocol::Scp,
|
||||
username: Some(String::from("admin")),
|
||||
password: Some(String::from("password")),
|
||||
directory: Some(PathBuf::from("/home")),
|
||||
remote_path: Some(PathBuf::from("/home")),
|
||||
local_path: Some(PathBuf::from("/usr")),
|
||||
s3: None,
|
||||
smb: None,
|
||||
};
|
||||
@@ -273,9 +283,13 @@ mod tests {
|
||||
assert_eq!(bookmark.username.as_deref().unwrap(), "root");
|
||||
assert_eq!(bookmark.password.as_deref().unwrap(), "password");
|
||||
assert_eq!(
|
||||
bookmark.directory.as_deref().unwrap(),
|
||||
bookmark.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/tmp")
|
||||
);
|
||||
assert_eq!(
|
||||
bookmark.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/usr")
|
||||
);
|
||||
let bookmark: &Bookmark = hosts
|
||||
.recents
|
||||
.get(&String::from("ISO20201218T181432"))
|
||||
@@ -286,9 +300,13 @@ mod tests {
|
||||
assert_eq!(bookmark.username.as_deref().unwrap(), "admin");
|
||||
assert_eq!(bookmark.password.as_deref().unwrap(), "password");
|
||||
assert_eq!(
|
||||
bookmark.directory.as_deref().unwrap(),
|
||||
bookmark.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/home")
|
||||
);
|
||||
assert_eq!(
|
||||
bookmark.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/usr")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -300,7 +318,8 @@ mod tests {
|
||||
password: Some(String::from("omar")),
|
||||
});
|
||||
let params: FileTransferParams = FileTransferParams::new(FileTransferProtocol::Scp, params)
|
||||
.entry_directory(Some(PathBuf::from("/home")));
|
||||
.remote_path(Some(PathBuf::from("/home")))
|
||||
.local_path(Some(PathBuf::from("/tmp")));
|
||||
let bookmark = Bookmark::from(params);
|
||||
assert_eq!(bookmark.protocol, FileTransferProtocol::Scp);
|
||||
assert_eq!(bookmark.address.as_deref().unwrap(), "127.0.0.1");
|
||||
@@ -308,9 +327,13 @@ mod tests {
|
||||
assert_eq!(bookmark.username.as_deref().unwrap(), "root");
|
||||
assert_eq!(bookmark.password.as_deref().unwrap(), "omar");
|
||||
assert_eq!(
|
||||
bookmark.directory.as_deref().unwrap(),
|
||||
bookmark.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/home")
|
||||
);
|
||||
assert_eq!(
|
||||
bookmark.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/tmp")
|
||||
);
|
||||
assert!(bookmark.s3.is_none());
|
||||
}
|
||||
|
||||
@@ -345,16 +368,21 @@ mod tests {
|
||||
protocol: FileTransferProtocol::Sftp,
|
||||
username: Some(String::from("root")),
|
||||
password: Some(String::from("password")),
|
||||
directory: Some(PathBuf::from("/tmp")),
|
||||
remote_path: Some(PathBuf::from("/tmp")),
|
||||
local_path: Some(PathBuf::from("/usr")),
|
||||
s3: None,
|
||||
smb: None,
|
||||
};
|
||||
let params = FileTransferParams::from(bookmark);
|
||||
assert_eq!(params.protocol, FileTransferProtocol::Sftp);
|
||||
assert_eq!(
|
||||
params.entry_directory.as_deref().unwrap(),
|
||||
params.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/tmp")
|
||||
);
|
||||
assert_eq!(
|
||||
params.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/usr")
|
||||
);
|
||||
let gparams = params.params.generic_params().unwrap();
|
||||
assert_eq!(gparams.address.as_str(), "192.168.1.1");
|
||||
assert_eq!(gparams.port, 22);
|
||||
@@ -370,7 +398,8 @@ mod tests {
|
||||
port: None,
|
||||
username: None,
|
||||
password: None,
|
||||
directory: Some(PathBuf::from("/tmp")),
|
||||
remote_path: Some(PathBuf::from("/tmp")),
|
||||
local_path: Some(PathBuf::from("/usr")),
|
||||
s3: Some(S3Params {
|
||||
bucket: String::from("veeso"),
|
||||
region: Some(String::from("eu-west-1")),
|
||||
@@ -385,9 +414,13 @@ mod tests {
|
||||
let params = FileTransferParams::from(bookmark);
|
||||
assert_eq!(params.protocol, FileTransferProtocol::AwsS3);
|
||||
assert_eq!(
|
||||
params.entry_directory.as_deref().unwrap(),
|
||||
params.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/tmp")
|
||||
);
|
||||
assert_eq!(
|
||||
params.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/usr")
|
||||
);
|
||||
let gparams = params.params.s3_params().unwrap();
|
||||
assert_eq!(gparams.bucket_name.as_str(), "veeso");
|
||||
assert_eq!(gparams.region.as_deref().unwrap(), "eu-west-1");
|
||||
@@ -407,7 +440,8 @@ mod tests {
|
||||
port: Some(445),
|
||||
username: Some("foo".to_string()),
|
||||
password: Some("bar".to_string()),
|
||||
directory: Some(PathBuf::from("/tmp")),
|
||||
remote_path: Some(PathBuf::from("/tmp")),
|
||||
local_path: Some(PathBuf::from("/usr")),
|
||||
s3: None,
|
||||
smb: Some(SmbParams {
|
||||
share: "test".to_string(),
|
||||
@@ -418,9 +452,13 @@ mod tests {
|
||||
let params = FileTransferParams::from(bookmark);
|
||||
assert_eq!(params.protocol, FileTransferProtocol::Smb);
|
||||
assert_eq!(
|
||||
params.entry_directory.as_deref().unwrap(),
|
||||
params.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/tmp")
|
||||
);
|
||||
assert_eq!(
|
||||
params.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/usr")
|
||||
);
|
||||
let smb_params = params.params.smb_params().unwrap();
|
||||
assert_eq!(smb_params.address.as_str(), "localhost");
|
||||
assert_eq!(smb_params.port, 445);
|
||||
@@ -439,7 +477,8 @@ mod tests {
|
||||
port: Some(445),
|
||||
username: None,
|
||||
password: None,
|
||||
directory: Some(PathBuf::from("/tmp")),
|
||||
remote_path: Some(PathBuf::from("/tmp")),
|
||||
local_path: Some(PathBuf::from("/usr")),
|
||||
s3: None,
|
||||
smb: Some(SmbParams {
|
||||
share: "test".to_string(),
|
||||
@@ -450,9 +489,13 @@ mod tests {
|
||||
let params = FileTransferParams::from(bookmark);
|
||||
assert_eq!(params.protocol, FileTransferProtocol::Smb);
|
||||
assert_eq!(
|
||||
params.entry_directory.as_deref().unwrap(),
|
||||
params.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/tmp")
|
||||
);
|
||||
assert_eq!(
|
||||
params.local_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/usr")
|
||||
);
|
||||
let smb_params = params.params.smb_params().unwrap();
|
||||
assert_eq!(smb_params.address.as_str(), "localhost");
|
||||
assert_eq!(smb_params.share.as_str(), "test");
|
||||
|
||||
Reference in New Issue
Block a user