Working on sync

This commit is contained in:
veeso
2021-05-02 21:04:03 +02:00
parent cbe242bb94
commit 2f0b340fe0
4 changed files with 204 additions and 86 deletions

View File

@@ -32,36 +32,156 @@ use tuirealm::{Payload, Value};
use std::path::PathBuf;
impl FileTransferActivity {
/// ### action_enter_local_dir
///
/// Enter a directory on local host from entry
/// Return true whether the directory changed
pub(super) fn action_enter_local_dir(&mut self, entry: FsEntry) -> bool {
match entry {
FsEntry::Directory(dir) => {
self.remote_changedir(dir.abs_path.as_path(), true);
if self.browser.sync_browsing {
self.action_change_remote_dir(dir.name.clone());
}
true
}
FsEntry::File(file) => {
match &file.symlink {
Some(symlink_entry) => {
// If symlink and is directory, point to symlink
match &**symlink_entry {
FsEntry::Directory(dir) => {
self.remote_changedir(dir.abs_path.as_path(), true);
// Check whether to sync
if self.browser.sync_browsing {
self.action_change_remote_dir(dir.name.clone());
}
true
}
_ => false,
}
}
None => false,
}
}
}
}
/// ### action_enter_remote_dir
///
/// Enter a directory on local host from entry
/// Return true whether the directory changed
pub(super) fn action_enter_remote_dir(&mut self, entry: FsEntry) -> bool {
match entry {
FsEntry::Directory(dir) => {
self.local_changedir(dir.abs_path.as_path(), true);
if self.browser.sync_browsing {
self.action_change_local_dir(dir.name.clone());
}
true
}
FsEntry::File(file) => {
match &file.symlink {
Some(symlink_entry) => {
// If symlink and is directory, point to symlink
match &**symlink_entry {
FsEntry::Directory(dir) => {
self.local_changedir(dir.abs_path.as_path(), true);
// Check whether to sync
if self.browser.sync_browsing {
self.action_change_local_dir(dir.name.clone());
}
true
}
_ => false,
}
}
None => false,
}
}
}
}
/// ### action_change_local_dir
///
/// Change local directory reading value from input
pub(super) fn action_change_local_dir(&mut self, input: String) {
let dir_path: PathBuf = PathBuf::from(input.as_str());
let abs_dir_path: PathBuf = match dir_path.is_relative() {
true => {
let mut d: PathBuf = self.local.wrkdir.clone();
d.push(dir_path);
d
}
false => dir_path,
};
self.local_changedir(abs_dir_path.as_path(), true);
let dir_path: PathBuf = self.local_to_abs_path(PathBuf::from(input.as_str()).as_path());
self.local_changedir(dir_path.as_path(), true);
// Check whether to sync
if self.browser.sync_browsing {
self.action_change_remote_dir(input);
}
}
/// ### action_change_remote_dir
///
/// Change remote directory reading value from input
pub(super) fn action_change_remote_dir(&mut self, input: String) {
let dir_path: PathBuf = PathBuf::from(input.as_str());
let abs_dir_path: PathBuf = match dir_path.is_relative() {
true => {
let mut wrkdir: PathBuf = self.remote.wrkdir.clone();
wrkdir.push(dir_path);
wrkdir
let dir_path: PathBuf = self.remote_to_abs_path(PathBuf::from(input.as_str()).as_path());
self.remote_changedir(dir_path.as_path(), true);
// Check whether to sync
if self.browser.sync_browsing {
self.action_change_local_dir(input);
}
}
/// ### action_go_to_previous_local_dir
///
/// Go to previous directory from localhost
pub(super) fn action_go_to_previous_local_dir(&mut self) {
if let Some(d) = self.local.popd() {
self.local_changedir(d.as_path(), false);
// Check whether to sync
if self.browser.sync_browsing {
self.action_go_to_previous_remote_dir();
}
false => dir_path,
};
self.remote_changedir(abs_dir_path.as_path(), true);
}
}
/// ### action_go_to_previous_remote_dir
///
/// Go to previous directory from remote host
pub(super) fn action_go_to_previous_remote_dir(&mut self) {
if let Some(d) = self.local.popd() {
self.remote_changedir(d.as_path(), false);
// Check whether to sync
if self.browser.sync_browsing {
self.action_go_to_previous_local_dir();
}
}
}
/// ### action_go_to_local_upper_dir
///
/// Go to upper directory on local host
pub(super) fn action_go_to_local_upper_dir(&mut self) {
// Get pwd
let path: PathBuf = self.local.wrkdir.clone();
// Go to parent directory
if let Some(parent) = path.as_path().parent() {
self.local_changedir(parent, true);
// If sync is enabled update remote too
if self.browser.sync_browsing {
self.action_go_to_remote_upper_dir();
}
}
}
/// #### action_go_to_remote_upper_dir
///
/// Go to upper directory on remote host
pub(super) fn action_go_to_remote_upper_dir(&mut self) {
// Get pwd
let path: PathBuf = self.remote.wrkdir.clone();
// Go to parent directory
if let Some(parent) = path.as_path().parent() {
self.remote_changedir(parent, true);
// If sync is enabled update local too
if self.browser.sync_browsing {
self.action_go_to_local_upper_dir();
}
}
}
/// ### action_local_copy