mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Optimized code for fsentry
This commit is contained in:
@@ -550,10 +550,7 @@ impl FileTransfer for ScpFileTransfer {
|
|||||||
match self.is_connected() {
|
match self.is_connected() {
|
||||||
true => {
|
true => {
|
||||||
// Get path
|
// Get path
|
||||||
let path: PathBuf = match file {
|
let path: PathBuf = file.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
let p: PathBuf = self.wrkdir.clone();
|
let p: PathBuf = self.wrkdir.clone();
|
||||||
match self.perform_shell_cmd_with_path(
|
match self.perform_shell_cmd_with_path(
|
||||||
p.as_path(),
|
p.as_path(),
|
||||||
@@ -589,10 +586,7 @@ impl FileTransfer for ScpFileTransfer {
|
|||||||
match self.is_connected() {
|
match self.is_connected() {
|
||||||
true => {
|
true => {
|
||||||
// Get path
|
// Get path
|
||||||
let path: PathBuf = match file {
|
let path: PathBuf = file.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
let p: PathBuf = self.wrkdir.clone();
|
let p: PathBuf = self.wrkdir.clone();
|
||||||
match self.perform_shell_cmd_with_path(
|
match self.perform_shell_cmd_with_path(
|
||||||
p.as_path(),
|
p.as_path(),
|
||||||
|
|||||||
@@ -461,10 +461,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
// Resolve destination path
|
// Resolve destination path
|
||||||
let abs_dst: PathBuf = self.get_abs_path(dst);
|
let abs_dst: PathBuf = self.get_abs_path(dst);
|
||||||
// Get abs path of entry
|
// Get abs path of entry
|
||||||
let abs_src: PathBuf = match file {
|
let abs_src: PathBuf = file.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
match sftp.rename(abs_src.as_path(), abs_dst.as_path(), None) {
|
match sftp.rename(abs_src.as_path(), abs_dst.as_path(), None) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(FileTransferError::new_ex(
|
Err(err) => Err(FileTransferError::new_ex(
|
||||||
|
|||||||
@@ -244,10 +244,7 @@ impl Localhost {
|
|||||||
///
|
///
|
||||||
/// Rename file or directory to new name
|
/// Rename file or directory to new name
|
||||||
pub fn rename(&mut self, entry: &FsEntry, dst_path: &Path) -> Result<(), HostError> {
|
pub fn rename(&mut self, entry: &FsEntry, dst_path: &Path) -> Result<(), HostError> {
|
||||||
let abs_path: PathBuf = match entry {
|
let abs_path: PathBuf = entry.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(f) => f.abs_path.clone(),
|
|
||||||
};
|
|
||||||
match std::fs::rename(abs_path.as_path(), dst_path) {
|
match std::fs::rename(abs_path.as_path(), dst_path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Scan dir
|
// Scan dir
|
||||||
|
|||||||
@@ -147,10 +147,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
// Check if file entry exists
|
// Check if file entry exists
|
||||||
if let Some(entry) = self.local.files.get(self.local.index) {
|
if let Some(entry) = self.local.files.get(self.local.index) {
|
||||||
let full_path: PathBuf = match entry {
|
let full_path: PathBuf = entry.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
// Rename file or directory and report status as popup
|
// Rename file or directory and report status as popup
|
||||||
match self
|
match self
|
||||||
.context
|
.context
|
||||||
@@ -194,10 +191,7 @@ impl FileTransferActivity {
|
|||||||
FileExplorerTab::Remote => {
|
FileExplorerTab::Remote => {
|
||||||
// Check if file entry exists
|
// Check if file entry exists
|
||||||
if let Some(entry) = self.remote.files.get(self.remote.index) {
|
if let Some(entry) = self.remote.files.get(self.remote.index) {
|
||||||
let full_path: PathBuf = match entry {
|
let full_path: PathBuf = entry.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
// Rename file or directory and report status as popup
|
// Rename file or directory and report status as popup
|
||||||
let dst_path: PathBuf = PathBuf::from(input);
|
let dst_path: PathBuf = PathBuf::from(input);
|
||||||
match self.client.rename(entry, dst_path.as_path()) {
|
match self.client.rename(entry, dst_path.as_path()) {
|
||||||
@@ -247,10 +241,7 @@ impl FileTransferActivity {
|
|||||||
FileExplorerTab::Local => {
|
FileExplorerTab::Local => {
|
||||||
// Check if file entry exists
|
// Check if file entry exists
|
||||||
if let Some(entry) = self.local.files.get(self.local.index) {
|
if let Some(entry) = self.local.files.get(self.local.index) {
|
||||||
let full_path: PathBuf = match entry {
|
let full_path: PathBuf = entry.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
// Delete file or directory and report status as popup
|
// Delete file or directory and report status as popup
|
||||||
match self.context.as_mut().unwrap().local.remove(entry) {
|
match self.context.as_mut().unwrap().local.remove(entry) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
@@ -283,10 +274,7 @@ impl FileTransferActivity {
|
|||||||
FileExplorerTab::Remote => {
|
FileExplorerTab::Remote => {
|
||||||
// Check if file entry exists
|
// Check if file entry exists
|
||||||
if let Some(entry) = self.remote.files.get(self.remote.index) {
|
if let Some(entry) = self.remote.files.get(self.remote.index) {
|
||||||
let full_path: PathBuf = match entry {
|
let full_path: PathBuf = entry.get_abs_path();
|
||||||
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
|
||||||
FsEntry::File(file) => file.abs_path.clone(),
|
|
||||||
};
|
|
||||||
// Delete file
|
// Delete file
|
||||||
match self.client.remove(entry) {
|
match self.client.remove(entry) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|||||||
@@ -474,10 +474,7 @@ impl FileTransferActivity {
|
|||||||
match &dir.symlink {
|
match &dir.symlink {
|
||||||
Some(symlink) => {
|
Some(symlink) => {
|
||||||
// Get symlink path
|
// Get symlink path
|
||||||
let symlink_path: &Path = match &**symlink {
|
let symlink_path: PathBuf = symlink.get_abs_path();
|
||||||
FsEntry::Directory(s_dir) => s_dir.abs_path.as_path(),
|
|
||||||
FsEntry::File(s_file) => s_file.abs_path.as_path(),
|
|
||||||
};
|
|
||||||
format!(
|
format!(
|
||||||
"{} => {}",
|
"{} => {}",
|
||||||
dir.abs_path.display(),
|
dir.abs_path.display(),
|
||||||
@@ -570,10 +567,7 @@ impl FileTransferActivity {
|
|||||||
match &file.symlink {
|
match &file.symlink {
|
||||||
Some(symlink) => {
|
Some(symlink) => {
|
||||||
// Get symlink path
|
// Get symlink path
|
||||||
let symlink_path: &Path = match &**symlink {
|
let symlink_path: PathBuf = symlink.get_abs_path();
|
||||||
FsEntry::Directory(s_dir) => s_dir.abs_path.as_path(),
|
|
||||||
FsEntry::File(s_file) => s_file.abs_path.as_path(),
|
|
||||||
};
|
|
||||||
format!(
|
format!(
|
||||||
"{} => {}",
|
"{} => {}",
|
||||||
file.abs_path.display(),
|
file.abs_path.display(),
|
||||||
|
|||||||
Reference in New Issue
Block a user