-
Notifications
You must be signed in to change notification settings - Fork 126
list: show symlink targets (for tar and zip) #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
f0dd6a4
632db3d
bd1898d
d972532
8313fd0
65cbd95
7ea0015
8b924ca
753288c
736ea65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,9 @@ pub struct FileInArchive { | |
|
|
||
| /// Whether this file is a directory | ||
| pub is_dir: bool, | ||
|
|
||
| /// The target of the symlink, if this file is a symlink | ||
| pub symlink_target: Option<PathBuf>, | ||
| } | ||
|
|
||
| /// Actually print the files | ||
|
|
@@ -41,21 +44,44 @@ pub fn list_files( | |
| tree.print(&mut out); | ||
| } else { | ||
| for file in files { | ||
| let FileInArchive { path, is_dir } = file?; | ||
| print_entry(&mut out, path.display(), is_dir); | ||
| let FileInArchive { | ||
| path, | ||
| is_dir, | ||
| symlink_target, | ||
| } = file?; | ||
| print_entry(&mut out, path.display(), is_dir, symlink_target); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Print an entry and highlight directories, either by coloring them | ||
| /// if that's supported or by adding a trailing / | ||
| fn print_entry(out: &mut impl Write, name: impl fmt::Display, is_dir: bool) { | ||
| fn print_entry(out: &mut impl Write, name: impl fmt::Display, is_dir: bool, symlink_target: Option<PathBuf>) { | ||
| use crate::utils::colors::*; | ||
|
|
||
| if !is_dir { | ||
| // Not a directory -> just print the file name | ||
| let _ = writeln!(out, "{name}"); | ||
| if let Some(target) = symlink_target { | ||
| if is_running_in_accessible_mode() { | ||
| // Accessible mode: use "->" for screen readers | ||
| let _ = writeln!(out, "{} -> {}", name, target.display()); | ||
| } else { | ||
| // Normal mode: use "->" with colors | ||
| let _ = writeln!( | ||
| out, | ||
| "{}{}{} -> {}{}{}", | ||
|
||
| *CYAN, | ||
| name, | ||
| *ALL_RESET, | ||
| *CYAN, | ||
| target.display(), | ||
| *ALL_RESET | ||
| ); | ||
| } | ||
| } else { | ||
| let _ = writeln!(out, "{name}"); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -151,11 +177,18 @@ mod tree { | |
| }; | ||
|
|
||
| let _ = write!(out, "{prefix}{final_part}"); | ||
| let is_dir = match self.file { | ||
| Some(FileInArchive { is_dir, .. }) => is_dir, | ||
| None => true, | ||
| let (is_dir, symlink_target) = match &self.file { | ||
| Some(FileInArchive { | ||
| is_dir, symlink_target, .. | ||
| }) => (*is_dir, symlink_target.clone()), | ||
| None => (true, None), | ||
| }; | ||
| super::print_entry(out, <Vec<u8> as ByteVec>::from_os_str_lossy(name).as_bstr(), is_dir); | ||
| super::print_entry( | ||
| out, | ||
| <Vec<u8> as ByteVec>::from_os_str_lossy(name).as_bstr(), | ||
| is_dir, | ||
| symlink_target, | ||
| ); | ||
|
|
||
| // Construct prefix for children, adding either a line if this isn't | ||
| // the last entry in the parent dir or empty space if it is. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we added
->, nowouch listcan't be used in scripts to provide a file list 🤔 .Can you add a check for, when
--quietis set but--treeisn't, we don't print out the arrow nor the target? This way you can stillouch list -q | xargs rm -ieven if there is a symlink in it.Let me know if you think there is a better and simpler approach, to allow for -> but keeping this compatible with scripts.