mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Optimized code, with the newest fsentry methods
This commit is contained in:
@@ -331,7 +331,7 @@ impl FileTransferActivity {
|
||||
// Get file at index
|
||||
if let Some(entry) = files.get(self.local.index) {
|
||||
// Call send (upload)
|
||||
self.filetransfer_send(entry, wrkdir.as_path(), Some(input));
|
||||
self.filetransfer_send(&entry.get_realfile(), wrkdir.as_path(), Some(input));
|
||||
}
|
||||
}
|
||||
FileExplorerTab::Remote => {
|
||||
@@ -340,7 +340,7 @@ impl FileTransferActivity {
|
||||
if let Some(entry) = files.get(self.remote.index) {
|
||||
// Call receive (download)
|
||||
self.filetransfer_recv(
|
||||
entry,
|
||||
&entry.get_realfile(),
|
||||
self.context.as_ref().unwrap().local.pwd().as_path(),
|
||||
Some(input),
|
||||
);
|
||||
|
||||
@@ -465,204 +465,133 @@ impl FileTransferActivity {
|
||||
};
|
||||
// Get file_name and fill info list
|
||||
let file_name: String = match fsentry {
|
||||
Some(fsentry) => match fsentry {
|
||||
FsEntry::Directory(dir) => {
|
||||
// Push path
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Path: ", Style::default()),
|
||||
Span::styled(
|
||||
match &dir.symlink {
|
||||
Some(symlink) => {
|
||||
// Get symlink path
|
||||
let symlink_path: PathBuf = symlink.get_abs_path();
|
||||
format!(
|
||||
"{} => {}",
|
||||
dir.abs_path.display(),
|
||||
symlink_path.display()
|
||||
)
|
||||
}
|
||||
None => dir.abs_path.to_string_lossy().to_string(),
|
||||
},
|
||||
Style::default()
|
||||
.fg(Color::LightYellow)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push creation time
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Creation time: ", Style::default()),
|
||||
Span::styled(
|
||||
time_to_str(dir.creation_time, "%b %d %Y %H:%M:%S"),
|
||||
Style::default()
|
||||
.fg(Color::LightGreen)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push Last change
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Last change time: ", Style::default()),
|
||||
Span::styled(
|
||||
time_to_str(dir.last_change_time, "%b %d %Y %H:%M:%S"),
|
||||
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push Last access
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Last access time: ", Style::default()),
|
||||
Span::styled(
|
||||
time_to_str(dir.last_access_time, "%b %d %Y %H:%M:%S"),
|
||||
Style::default()
|
||||
.fg(Color::LightMagenta)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// User
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
let username: String = match dir.user {
|
||||
Some(uid) => match get_user_by_uid(uid) {
|
||||
Some(user) => user.name().to_string_lossy().to_string(),
|
||||
None => uid.to_string(),
|
||||
Some(fsentry) => {
|
||||
// Get name and path
|
||||
let abs_path: PathBuf = fsentry.get_abs_path();
|
||||
let name: String = fsentry.get_name();
|
||||
let ctime: String = time_to_str(fsentry.get_creation_time(), "%b %d %Y %H:%M:%S");
|
||||
let atime: String =
|
||||
time_to_str(fsentry.get_last_access_time(), "%b %d %Y %H:%M:%S");
|
||||
let mtime: String = time_to_str(fsentry.get_creation_time(), "%b %d %Y %H:%M:%S");
|
||||
let (bsize, size): (ByteSize, usize) =
|
||||
(ByteSize(fsentry.get_size() as u64), fsentry.get_size());
|
||||
let user: Option<u32> = fsentry.get_user();
|
||||
let group: Option<u32> = fsentry.get_group();
|
||||
let real_path: Option<PathBuf> = {
|
||||
let real_file: FsEntry = fsentry.get_realfile();
|
||||
match real_file.get_abs_path() != abs_path {
|
||||
true => Some(real_file.get_abs_path()),
|
||||
false => None,
|
||||
}
|
||||
};
|
||||
// Push path
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Path: ", Style::default()),
|
||||
Span::styled(
|
||||
match real_path {
|
||||
Some(symlink) => {
|
||||
format!("{} => {}", abs_path.display(), symlink.display())
|
||||
}
|
||||
None => abs_path.to_string_lossy().to_string(),
|
||||
},
|
||||
None => String::from("0"),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let username: String = format!("{}", dir.user.unwrap_or(0));
|
||||
Style::default()
|
||||
.fg(Color::LightYellow)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push file type
|
||||
if let Some(ftype) = fsentry.get_ftype() {
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("User: ", Style::default()),
|
||||
Span::styled("File type: ", Style::default()),
|
||||
Span::styled(
|
||||
username,
|
||||
ftype,
|
||||
Style::default()
|
||||
.fg(Color::LightRed)
|
||||
.fg(Color::Green)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Group
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
let group: String = match dir.group {
|
||||
Some(gid) => match get_group_by_gid(gid) {
|
||||
Some(group) => group.name().to_string_lossy().to_string(),
|
||||
None => gid.to_string(),
|
||||
},
|
||||
None => String::from("0"),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let group: String = format!("{}", dir.group.unwrap_or(0));
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Group: ", Style::default()),
|
||||
Span::styled(
|
||||
group,
|
||||
Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Finally return file name
|
||||
dir.name.clone()
|
||||
}
|
||||
FsEntry::File(file) => {
|
||||
// Push path
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Path: ", Style::default()),
|
||||
Span::styled(
|
||||
match &file.symlink {
|
||||
Some(symlink) => {
|
||||
// Get symlink path
|
||||
let symlink_path: PathBuf = symlink.get_abs_path();
|
||||
format!(
|
||||
"{} => {}",
|
||||
file.abs_path.display(),
|
||||
symlink_path.display()
|
||||
)
|
||||
}
|
||||
None => file.abs_path.to_string_lossy().to_string(),
|
||||
},
|
||||
Style::default()
|
||||
.fg(Color::LightYellow)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push size
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Size: ", Style::default()),
|
||||
Span::styled(
|
||||
format!("{} ({})", ByteSize(file.size as u64), file.size),
|
||||
Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push creation time
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Creation time: ", Style::default()),
|
||||
Span::styled(
|
||||
time_to_str(file.creation_time, "%b %d %Y %H:%M:%S"),
|
||||
Style::default()
|
||||
.fg(Color::LightGreen)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push Last change
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Last change time: ", Style::default()),
|
||||
Span::styled(
|
||||
time_to_str(file.last_change_time, "%b %d %Y %H:%M:%S"),
|
||||
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push Last access
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Last access time: ", Style::default()),
|
||||
Span::styled(
|
||||
time_to_str(file.last_access_time, "%b %d %Y %H:%M:%S"),
|
||||
Style::default()
|
||||
.fg(Color::LightMagenta)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// User
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
let username: String = match file.user {
|
||||
Some(uid) => match get_user_by_uid(uid) {
|
||||
Some(user) => user.name().to_string_lossy().to_string(),
|
||||
None => uid.to_string(),
|
||||
},
|
||||
None => String::from("0"),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let username: String = format!("{}", file.user.unwrap_or(0));
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("User: ", Style::default()),
|
||||
Span::styled(
|
||||
username,
|
||||
Style::default()
|
||||
.fg(Color::LightRed)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Group
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
let group: String = match file.group {
|
||||
Some(gid) => match get_group_by_gid(gid) {
|
||||
Some(group) => group.name().to_string_lossy().to_string(),
|
||||
None => gid.to_string(),
|
||||
},
|
||||
None => String::from("0"),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let group: String = format!("{}", file.group.unwrap_or(0));
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Group: ", Style::default()),
|
||||
Span::styled(
|
||||
group,
|
||||
Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Finally return file name
|
||||
file.name.clone()
|
||||
}
|
||||
},
|
||||
// Push size
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Size: ", Style::default()),
|
||||
Span::styled(
|
||||
format!("{} ({})", bsize, size),
|
||||
Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push creation time
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Creation time: ", Style::default()),
|
||||
Span::styled(
|
||||
ctime,
|
||||
Style::default()
|
||||
.fg(Color::LightGreen)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push Last change
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Last change time: ", Style::default()),
|
||||
Span::styled(
|
||||
mtime,
|
||||
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Push Last access
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Last access time: ", Style::default()),
|
||||
Span::styled(
|
||||
atime,
|
||||
Style::default()
|
||||
.fg(Color::LightMagenta)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// User
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
let username: String = match user {
|
||||
Some(uid) => match get_user_by_uid(uid) {
|
||||
Some(user) => user.name().to_string_lossy().to_string(),
|
||||
None => uid.to_string(),
|
||||
},
|
||||
None => String::from("0"),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let username: String = format!("{}", user.unwrap_or(0));
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("User: ", Style::default()),
|
||||
Span::styled(
|
||||
username,
|
||||
Style::default()
|
||||
.fg(Color::LightRed)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Group
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
let group: String = match group {
|
||||
Some(gid) => match get_group_by_gid(gid) {
|
||||
Some(group) => group.name().to_string_lossy().to_string(),
|
||||
None => gid.to_string(),
|
||||
},
|
||||
None => String::from("0"),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let group: String = format!("{}", group.unwrap_or(0));
|
||||
info.push(ListItem::new(Spans::from(vec![
|
||||
Span::styled("Group: ", Style::default()),
|
||||
Span::styled(
|
||||
group,
|
||||
Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])));
|
||||
// Finally return file name
|
||||
name
|
||||
}
|
||||
None => String::from(""),
|
||||
};
|
||||
List::new(info)
|
||||
|
||||
Reference in New Issue
Block a user