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