mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Working on sync
This commit is contained in:
@@ -32,36 +32,156 @@ use tuirealm::{Payload, Value};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
impl FileTransferActivity {
|
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
|
/// ### action_change_local_dir
|
||||||
///
|
///
|
||||||
/// Change local directory reading value from input
|
/// Change local directory reading value from input
|
||||||
pub(super) fn action_change_local_dir(&mut self, input: String) {
|
pub(super) fn action_change_local_dir(&mut self, input: String) {
|
||||||
let dir_path: PathBuf = PathBuf::from(input.as_str());
|
let dir_path: PathBuf = self.local_to_abs_path(PathBuf::from(input.as_str()).as_path());
|
||||||
let abs_dir_path: PathBuf = match dir_path.is_relative() {
|
self.local_changedir(dir_path.as_path(), true);
|
||||||
true => {
|
// Check whether to sync
|
||||||
let mut d: PathBuf = self.local.wrkdir.clone();
|
if self.browser.sync_browsing {
|
||||||
d.push(dir_path);
|
self.action_change_remote_dir(input);
|
||||||
d
|
}
|
||||||
}
|
|
||||||
false => dir_path,
|
|
||||||
};
|
|
||||||
self.local_changedir(abs_dir_path.as_path(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### action_change_remote_dir
|
/// ### action_change_remote_dir
|
||||||
///
|
///
|
||||||
/// Change remote directory reading value from input
|
/// Change remote directory reading value from input
|
||||||
pub(super) fn action_change_remote_dir(&mut self, input: String) {
|
pub(super) fn action_change_remote_dir(&mut self, input: String) {
|
||||||
let dir_path: PathBuf = PathBuf::from(input.as_str());
|
let dir_path: PathBuf = self.remote_to_abs_path(PathBuf::from(input.as_str()).as_path());
|
||||||
let abs_dir_path: PathBuf = match dir_path.is_relative() {
|
self.remote_changedir(dir_path.as_path(), true);
|
||||||
true => {
|
// Check whether to sync
|
||||||
let mut wrkdir: PathBuf = self.remote.wrkdir.clone();
|
if self.browser.sync_browsing {
|
||||||
wrkdir.push(dir_path);
|
self.action_change_local_dir(input);
|
||||||
wrkdir
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ### 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
|
/// ### action_local_copy
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ use crate::system::environment;
|
|||||||
use crate::system::sshkey_storage::SshKeyStorage;
|
use crate::system::sshkey_storage::SshKeyStorage;
|
||||||
// Ext
|
// Ext
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
impl FileTransferActivity {
|
impl FileTransferActivity {
|
||||||
/// ### log
|
/// ### log
|
||||||
@@ -175,4 +175,32 @@ impl FileTransferActivity {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### local_to_abs_path
|
||||||
|
///
|
||||||
|
/// Convert a path to absolute according to local explorer
|
||||||
|
pub(super) fn local_to_abs_path(&self, path: &Path) -> PathBuf {
|
||||||
|
match path.is_relative() {
|
||||||
|
true => {
|
||||||
|
let mut d: PathBuf = self.local.wrkdir.clone();
|
||||||
|
d.push(path);
|
||||||
|
d
|
||||||
|
}
|
||||||
|
false => path.to_path_buf(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ### remote_to_abs_path
|
||||||
|
///
|
||||||
|
/// Convert a path to absolute according to remote explorer
|
||||||
|
pub(super) fn remote_to_abs_path(&self, path: &Path) -> PathBuf {
|
||||||
|
match path.is_relative() {
|
||||||
|
true => {
|
||||||
|
let mut wrkdir: PathBuf = self.remote.wrkdir.clone();
|
||||||
|
wrkdir.push(path);
|
||||||
|
wrkdir
|
||||||
|
}
|
||||||
|
false => path.to_path_buf(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -749,12 +749,6 @@ impl FileTransferActivity {
|
|||||||
if push {
|
if push {
|
||||||
self.local.pushd(prev_dir.as_path())
|
self.local.pushd(prev_dir.as_path())
|
||||||
}
|
}
|
||||||
// @! if synchronized browsing is enabled, change directory on remote too ~ since 0.5.0
|
|
||||||
if self.browser.sync_browsing {
|
|
||||||
if let Some(name) = path.file_name() {
|
|
||||||
self.remote_changedir(PathBuf::from(name).as_path(), push);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
@@ -784,13 +778,6 @@ impl FileTransferActivity {
|
|||||||
if push {
|
if push {
|
||||||
self.remote.pushd(prev_dir.as_path())
|
self.remote.pushd(prev_dir.as_path())
|
||||||
}
|
}
|
||||||
// @! if synchronized browsing is enabled, change directory on local too ~ since 0.5.0
|
|
||||||
if self.browser.sync_browsing {
|
|
||||||
if let Some(name) = path.file_name() {
|
|
||||||
self.local_changedir(PathBuf::from(name).as_path(), push);
|
|
||||||
// TODO: move this somewhere else, since it's calling recursively
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
|
|||||||
@@ -73,8 +73,9 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_BACKSPACE) => {
|
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_BACKSPACE) => {
|
||||||
// Go to previous directory
|
// Go to previous directory
|
||||||
if let Some(d) = self.local.popd() {
|
self.action_go_to_previous_local_dir();
|
||||||
self.local_changedir(d.as_path(), false);
|
if self.browser.sync_browsing {
|
||||||
|
let _ = self.update_remote_filelist();
|
||||||
}
|
}
|
||||||
// Reload file list component
|
// Reload file list component
|
||||||
self.update_local_filelist()
|
self.update_local_filelist()
|
||||||
@@ -86,25 +87,14 @@ impl FileTransferActivity {
|
|||||||
entry = Some(e.clone());
|
entry = Some(e.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = entry {
|
if let Some(entry) = entry {
|
||||||
// If directory, enter directory, otherwise check if symlink
|
if self.action_enter_local_dir(entry) {
|
||||||
match entry {
|
// Update file list if sync
|
||||||
FsEntry::Directory(dir) => {
|
if self.browser.sync_browsing {
|
||||||
self.local_changedir(dir.abs_path.as_path(), true);
|
let _ = self.update_remote_filelist();
|
||||||
self.update_local_filelist()
|
|
||||||
}
|
|
||||||
FsEntry::File(file) => {
|
|
||||||
// Check if symlink
|
|
||||||
match &file.symlink {
|
|
||||||
Some(pointer) => match &**pointer {
|
|
||||||
FsEntry::Directory(dir) => {
|
|
||||||
self.local_changedir(dir.abs_path.as_path(), true);
|
|
||||||
self.update_local_filelist()
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.update_local_filelist()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -170,13 +160,11 @@ impl FileTransferActivity {
|
|||||||
self.update_local_filelist()
|
self.update_local_filelist()
|
||||||
}
|
}
|
||||||
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_U) => {
|
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_U) => {
|
||||||
// Get pwd
|
self.action_go_to_local_upper_dir();
|
||||||
let path: PathBuf = self.local.wrkdir.clone();
|
if self.browser.sync_browsing {
|
||||||
// Go to parent directory
|
let _ = self.update_remote_filelist();
|
||||||
if let Some(parent) = path.as_path().parent() {
|
|
||||||
self.local_changedir(parent, true);
|
|
||||||
// Reload file list component
|
|
||||||
}
|
}
|
||||||
|
// Reload file list component
|
||||||
self.update_local_filelist()
|
self.update_local_filelist()
|
||||||
}
|
}
|
||||||
// -- remote tab
|
// -- remote tab
|
||||||
@@ -193,27 +181,14 @@ impl FileTransferActivity {
|
|||||||
entry = Some(e.clone());
|
entry = Some(e.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = entry {
|
if let Some(entry) = entry {
|
||||||
// If directory, enter directory; if file, check if is symlink
|
if self.action_enter_remote_dir(entry) {
|
||||||
match entry {
|
// Update file list if sync
|
||||||
FsEntry::Directory(dir) => {
|
if self.browser.sync_browsing {
|
||||||
self.remote_changedir(dir.abs_path.as_path(), true);
|
let _ = self.update_local_filelist();
|
||||||
self.update_remote_filelist()
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
self.update_remote_filelist()
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.update_remote_filelist()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -234,8 +209,10 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_BACKSPACE) => {
|
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_BACKSPACE) => {
|
||||||
// Go to previous directory
|
// Go to previous directory
|
||||||
if let Some(d) = self.remote.popd() {
|
self.action_go_to_previous_remote_dir();
|
||||||
self.remote_changedir(d.as_path(), false);
|
// If sync is enabled update local too
|
||||||
|
if self.browser.sync_browsing {
|
||||||
|
let _ = self.update_local_filelist();
|
||||||
}
|
}
|
||||||
// Reload file list component
|
// Reload file list component
|
||||||
self.update_remote_filelist()
|
self.update_remote_filelist()
|
||||||
@@ -286,11 +263,9 @@ impl FileTransferActivity {
|
|||||||
self.update_remote_filelist()
|
self.update_remote_filelist()
|
||||||
}
|
}
|
||||||
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_U) => {
|
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_U) => {
|
||||||
// Get pwd
|
self.action_go_to_remote_upper_dir();
|
||||||
let path: PathBuf = self.remote.wrkdir.clone();
|
if self.browser.sync_browsing {
|
||||||
// Go to parent directory
|
let _ = self.update_local_filelist();
|
||||||
if let Some(parent) = path.as_path().parent() {
|
|
||||||
self.remote_changedir(parent, true);
|
|
||||||
}
|
}
|
||||||
// Reload file list component
|
// Reload file list component
|
||||||
self.update_remote_filelist()
|
self.update_remote_filelist()
|
||||||
@@ -517,6 +492,14 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
// Umount
|
// Umount
|
||||||
self.umount_goto();
|
self.umount_goto();
|
||||||
|
// Reload files if sync
|
||||||
|
if self.browser.sync_browsing {
|
||||||
|
match self.tab {
|
||||||
|
FileExplorerTab::Remote => self.update_local_filelist(),
|
||||||
|
FileExplorerTab::Local => self.update_remote_filelist(),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
// Reload files
|
// Reload files
|
||||||
match self.tab {
|
match self.tab {
|
||||||
FileExplorerTab::Local => self.update_local_filelist(),
|
FileExplorerTab::Local => self.update_local_filelist(),
|
||||||
|
|||||||
Reference in New Issue
Block a user