FsEntry::*::symlink is now a Option<Box<FsEntry>>; this improved symlinks, which gave errors some times

This commit is contained in:
ChristianVisintin
2020-12-12 16:26:03 +01:00
parent 23ac5089a7
commit f73e43304e
8 changed files with 108 additions and 88 deletions

View File

@@ -118,43 +118,10 @@ impl FileTransferActivity {
}
FsEntry::File(file) => {
// Check if symlink
if let Some(realpath) = &file.symlink {
// Stat realpath
match self
.context
.as_ref()
.unwrap()
.local
.stat(realpath.as_path())
{
Ok(real_file) => {
// If real file is a directory, enter directory
if let FsEntry::Directory(real_dir) = real_file {
self.local_changedir(
real_dir.abs_path.as_path(),
true,
)
}
}
Err(err) => {
self.log(
LogLevel::Error,
format!(
"Failed to stat file \"{}\": {}",
realpath.display(),
err
)
.as_ref(),
);
self.input_mode = InputMode::Popup(PopupType::Alert(
Color::Red,
format!(
"Failed to stat file \"{}\": {}",
realpath.display(),
err
),
));
}
if let Some(symlink_entry) = &file.symlink {
// If symlink entry is a directory, go to directory
if let FsEntry::Directory(dir) = &**symlink_entry {
self.local_changedir(dir.abs_path.as_path(), true)
}
}
}
@@ -319,37 +286,10 @@ impl FileTransferActivity {
}
FsEntry::File(file) => {
// Check if symlink
if let Some(realpath) = &file.symlink {
// Stat realpath
match self.client.stat(realpath.as_path()) {
Ok(real_file) => {
// If real file is a directory, enter directory
if let FsEntry::Directory(real_dir) = real_file {
self.remote_changedir(
real_dir.abs_path.as_path(),
true,
)
}
}
Err(err) => {
self.log(
LogLevel::Error,
format!(
"Failed to stat file \"{}\": {}",
realpath.display(),
err
)
.as_ref(),
);
self.input_mode = InputMode::Popup(PopupType::Alert(
Color::Red,
format!(
"Failed to stat file \"{}\": {}",
realpath.display(),
err
),
));
}
if let Some(symlink_entry) = &file.symlink {
// If symlink entry is a directory, go to directory
if let FsEntry::Directory(dir) = &**symlink_entry {
self.remote_changedir(dir.abs_path.as_path(), true)
}
}
}

View File

@@ -473,7 +473,16 @@ impl FileTransferActivity {
Span::styled(
match &dir.symlink {
Some(symlink) => {
format!("{} => {}", dir.abs_path.display(), symlink.display())
// Get symlink path
let symlink_path: &Path = match &**symlink {
FsEntry::Directory(s_dir) => s_dir.abs_path.as_path(),
FsEntry::File(s_file) => s_file.abs_path.as_path(),
};
format!(
"{} => {}",
dir.abs_path.display(),
symlink_path.display()
)
}
None => dir.abs_path.to_string_lossy().to_string(),
},
@@ -560,7 +569,16 @@ impl FileTransferActivity {
Span::styled(
match &file.symlink {
Some(symlink) => {
format!("{} => {}", file.abs_path.display(), symlink.display())
// Get symlink path
let symlink_path: &Path = match &**symlink {
FsEntry::Directory(s_dir) => s_dir.abs_path.as_path(),
FsEntry::File(s_file) => s_file.abs_path.as_path(),
};
format!(
"{} => {}",
file.abs_path.display(),
symlink_path.display()
)
}
None => file.abs_path.to_string_lossy().to_string(),
},