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:
Christian Visintin
2023-07-06 16:05:22 +02:00
committed by GitHub
parent ee28d34f29
commit ca005cbecd
16 changed files with 261 additions and 98 deletions

View File

@@ -11,7 +11,8 @@ use super::FileTransferProtocol;
pub struct FileTransferParams {
pub protocol: FileTransferProtocol,
pub params: ProtocolParams,
pub entry_directory: Option<PathBuf>,
pub remote_path: Option<PathBuf>,
pub local_path: Option<PathBuf>,
}
/// Container for protocol params
@@ -64,13 +65,20 @@ impl FileTransferParams {
Self {
protocol,
params,
entry_directory: None,
remote_path: None,
local_path: None,
}
}
/// Set entry directory
pub fn entry_directory<P: AsRef<Path>>(mut self, dir: Option<P>) -> Self {
self.entry_directory = dir.map(|x| x.as_ref().to_path_buf());
/// Set remote directory
pub fn remote_path<P: AsRef<Path>>(mut self, dir: Option<P>) -> Self {
self.remote_path = dir.map(|x| x.as_ref().to_path_buf());
self
}
/// Set local directory
pub fn local_path<P: AsRef<Path>>(mut self, dir: Option<P>) -> Self {
self.local_path = dir.map(|x| x.as_ref().to_path_buf());
self
}
@@ -325,16 +333,15 @@ mod test {
fn test_filetransfer_params() {
let params: FileTransferParams =
FileTransferParams::new(FileTransferProtocol::Scp, ProtocolParams::default())
.entry_directory(Some(&Path::new("/tmp")));
.remote_path(Some(&Path::new("/tmp")))
.local_path(Some(&Path::new("/usr")));
assert_eq!(
params.params.generic_params().unwrap().address.as_str(),
"localhost"
);
assert_eq!(params.protocol, FileTransferProtocol::Scp);
assert_eq!(
params.entry_directory.as_deref().unwrap(),
Path::new("/tmp")
);
assert_eq!(params.remote_path.as_deref().unwrap(), Path::new("/tmp"));
assert_eq!(params.local_path.as_deref().unwrap(), Path::new("/usr"));
}
#[test]