Merge pull request #812 from yyogo/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Append trailing path separators to directories
authored by David Peter · committed by GitHub · parents dcde6d3, 41affe1 · Browse files · 10 files·+282 added−197 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+282 added−197 removed
- tests:+97 added−97 removed
- other:+185 added−100 removed
Provenance
- Commit
de27835- Tree
df92fa0- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
dcde6d3- Parent 2
41affe1
10 files changed+282 added−197 removed
modified:src/exec/job.rs+14 added-12 removed
1-use std::path::PathBuf;1 use std::sync::mpsc::Receiver;2 use std::sync::{Arc, Mutex};3 4+use crate::dir_entry::DirEntry;5 use crate::error::print_error;6 use crate::exit_codes::{merge_exitcodes, ExitCode};7 use crate::walk::WorkerResult;8 15 unmodified lines24 let lock = rx.lock().unwrap();25 26 // Obtain the next result from the receiver, else if the channel27 // has closed, exit from the loop28- let value: PathBuf = match lock.recv() {29- Ok(WorkerResult::Entry(path)) => path,28+ let dir_entry: DirEntry = match lock.recv() {29+ Ok(WorkerResult::Entry(dir_entry)) => dir_entry,30 Ok(WorkerResult::Error(err)) => {31 if show_filesystem_errors {32 print_error(err.to_string());33 }4 unmodified lines38 39 // Drop the lock so that other threads can read from the receiver.40 drop(lock);41 // Generate a command, execute it and store its exit code.42- results.push(cmd.execute(&value, Arc::clone(&out_perm), buffer_output))42+ results.push(cmd.execute(dir_entry.path(), Arc::clone(&out_perm), buffer_output))43 }44 // Returns error in case of any error.45 merge_exitcodes(results)46 }3 unmodified lines50 cmd: &CommandSet,51 show_filesystem_errors: bool,52 limit: usize,53 ) -> ExitCode {54+ let paths = rx55+ .into_iter()54- let paths = rx.iter().filter_map(|value| match value {55- WorkerResult::Entry(path) => Some(path),56- WorkerResult::Error(err) => {57- if show_filesystem_errors {58- print_error(err.to_string());56+ .filter_map(|worker_result| match worker_result {57+ WorkerResult::Entry(dir_entry) => Some(dir_entry.into_path()),58+ WorkerResult::Error(err) => {59+ if show_filesystem_errors {60+ print_error(err.to_string());61+ }62+ None63 }60- None61- }62- });64+ });65 if limit == 0 {66 // no limit67 return cmd.execute_batch(paths);68 }10 unmodified linesmodified:src/config.rs+3 added
109 unmodified lines110 111 /// The separator used to print file paths.112 pub path_separator: Option<String>,113 114+ /// The actual separator, either the system default separator or `path_separator`115+ pub actual_path_separator: String,116+117 /// The maximum number of search results118 pub max_results: Option<usize>,119 120 /// Whether or not to strip the './' prefix for search results2 unmodified linesadded:src/dir_entry.rs+92 added
1+use std::{2+ fs::{FileType, Metadata},3+ path::{Path, PathBuf},4+};5+6+use once_cell::unsync::OnceCell;7+8+enum DirEntryInner {9+ Normal(ignore::DirEntry),10+ BrokenSymlink(PathBuf),11+}12+13+pub struct DirEntry {14+ inner: DirEntryInner,15+ metadata: OnceCell<Option<Metadata>>,16+}17+18+impl DirEntry {19+ #[inline]20+ pub fn normal(e: ignore::DirEntry) -> Self {21+ Self {22+ inner: DirEntryInner::Normal(e),23+ metadata: OnceCell::new(),24+ }25+ }26+27+ pub fn broken_symlink(path: PathBuf) -> Self {28+ Self {29+ inner: DirEntryInner::BrokenSymlink(path),30+ metadata: OnceCell::new(),31+ }32+ }33+34+ pub fn path(&self) -> &Path {35+ match &self.inner {36+ DirEntryInner::Normal(e) => e.path(),37+ DirEntryInner::BrokenSymlink(pathbuf) => pathbuf.as_path(),38+ }39+ }40+41+ pub fn into_path(self) -> PathBuf {42+ match self.inner {43+ DirEntryInner::Normal(e) => e.into_path(),44+ DirEntryInner::BrokenSymlink(p) => p,45+ }46+ }47+48+ pub fn file_type(&self) -> Option<FileType> {49+ match &self.inner {50+ DirEntryInner::Normal(e) => e.file_type(),51+ DirEntryInner::BrokenSymlink(_) => self.metadata().map(|m| m.file_type()),52+ }53+ }54+55+ pub fn metadata(&self) -> Option<&Metadata> {56+ self.metadata57+ .get_or_init(|| match &self.inner {58+ DirEntryInner::Normal(e) => e.metadata().ok(),59+ DirEntryInner::BrokenSymlink(path) => path.symlink_metadata().ok(),60+ })61+ .as_ref()62+ }63+64+ pub fn depth(&self) -> Option<usize> {65+ match &self.inner {66+ DirEntryInner::Normal(e) => Some(e.depth()),67+ DirEntryInner::BrokenSymlink(_) => None,68+ }69+ }70+}71+72+impl PartialEq for DirEntry {73+ #[inline]74+ fn eq(&self, other: &Self) -> bool {75+ self.path() == other.path()76+ }77+}78+impl Eq for DirEntry {}79+80+impl PartialOrd for DirEntry {81+ #[inline]82+ fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {83+ self.path().partial_cmp(other.path())84+ }85+}86+87+impl Ord for DirEntry {88+ #[inline]89+ fn cmp(&self, other: &Self) -> std::cmp::Ordering {90+ self.path().cmp(other.path())91+ }92+}modified:src/filesystem.rs+2 added-2 removed
7 unmodified lines8 use std::path::{Path, PathBuf};9 10 use normpath::PathExt;11 12-use crate::walk;12+use crate::dir_entry;13 14 pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {15 if path.is_absolute() {16 return Ok(path.to_path_buf());33 unmodified lines50 pub fn is_executable(_: &fs::Metadata) -> bool {51 false52 }53 54-pub fn is_empty(entry: &walk::DirEntry) -> bool {54+pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {55 if let Some(file_type) = entry.file_type() {56 if file_type.is_dir() {57 if let Ok(mut entries) = fs::read_dir(entry.path()) {58 entries.next().is_none()90 unmodified linesmodified:src/filetypes.rs+2 added-2 removed
1+use crate::dir_entry;2 use crate::filesystem;2-use crate::walk;3 4 /// Whether or not to show5 #[derive(Default)]6 pub struct FileTypes {6 unmodified lines13 pub empty_only: bool,14 }15 16 impl FileTypes {17- pub fn should_ignore(&self, entry: &walk::DirEntry) -> bool {17+ pub fn should_ignore(&self, entry: &dir_entry::DirEntry) -> bool {18 if let Some(ref entry_type) = entry.file_type() {19 (!self.files && entry_type.is_file())20 || (!self.directories && entry_type.is_dir())21 || (!self.symlinks && entry_type.is_symlink())18 unmodified linesmodified:src/main.rs+5 added
1 mod app;2 mod config;3+mod dir_entry;4 mod error;5 mod exec;6 mod exit_codes;7 mod filesystem;213 unmodified lines221 222 let path_separator = matches223 .value_of("path-separator")224 .map_or_else(filesystem::default_path_separator, |s| Some(s.to_owned()));225+ let actual_path_separator = path_separator226+ .clone()227+ .unwrap_or_else(|| std::path::MAIN_SEPARATOR.to_string());228 check_path_separator_length(path_separator.as_deref())?;229 230 let size_limits = extract_size_limits(&matches)?;231 let time_constraints = extract_time_constraints(&matches)?;138 unmodified lines370 #[cfg(unix)]371 owner_constraint,372 show_filesystem_errors: matches.is_present("show-errors"),373 path_separator,374+ actual_path_separator,375 max_results: matches376 .value_of("max-results")377 .map(|n| n.parse::<usize>())378 .transpose()191 unmodified linesmodified:src/output.rs+56 added-17 removed
3 unmodified lines4 5 use lscolors::{Indicator, LsColors, Style};6 7 use crate::config::Config;8+use crate::dir_entry::DirEntry;9 use crate::error::print_error;10 use crate::exit_codes::ExitCode;11 use crate::filesystem::strip_current_dir;12 13 fn replace_path_separator(path: &str, new_path_separator: &str) -> String {14 path.replace(std::path::MAIN_SEPARATOR, new_path_separator)15 }16 16-// TODO: this function is performance critical and can probably be optimized17-pub fn print_entry<W: Write>(stdout: &mut W, entry: &Path, config: &Config) {18- let path = if config.strip_cwd_prefix {19- strip_current_dir(entry)17+fn stripped_path<'a>(entry: &'a DirEntry, config: &Config) -> &'a Path {18+ let path = entry.path();19+ if config.strip_cwd_prefix {20+ strip_current_dir(path)21 } else {21- entry22- };22+ path23+ }24+}25 26+// TODO: this function is performance critical and can probably be optimized27+pub fn print_entry<W: Write>(stdout: &mut W, entry: &DirEntry, config: &Config) {28 let r = if let Some(ref ls_colors) = config.ls_colors {25- print_entry_colorized(stdout, path, config, ls_colors)29+ print_entry_colorized(stdout, entry, config, ls_colors)30 } else {27- print_entry_uncolorized(stdout, path, config)31+ print_entry_uncolorized(stdout, entry, config)32 };33 34 if let Err(e) = r {35 if e.kind() == ::std::io::ErrorKind::BrokenPipe {5 unmodified lines41 }42 }43 }44 45+// Display a trailing slash if the path is a directory and the config option is enabled.46+// If the path_separator option is set, display that instead.47+// The trailing slash will not be colored.48+#[inline]49+fn print_trailing_slash<W: Write>(50+ stdout: &mut W,51+ entry: &DirEntry,52+ config: &Config,53+ style: Option<&Style>,54+) -> io::Result<()> {55+ if entry.file_type().map_or(false, |ft| ft.is_dir()) {56+ write!(57+ stdout,58+ "{}",59+ style60+ .map(Style::to_ansi_term_style)61+ .unwrap_or_default()62+ .paint(&config.actual_path_separator)63+ )?;64+ }65+ Ok(())66+}67+68 // TODO: this function is performance critical and can probably be optimized69 fn print_entry_colorized<W: Write>(70 stdout: &mut W,44- path: &Path,71+ entry: &DirEntry,72 config: &Config,73 ls_colors: &LsColors,74 ) -> io::Result<()> {75 // Split the path between the parent and the last component76 let mut offset = 0;77+ let path = stripped_path(entry, config);78 let path_str = path.to_string_lossy();79 80 if let Some(parent) = path.parent() {81 offset = parent.to_string_lossy().len();19 unmodified lines101 write!(stdout, "{}", style.paint(parent_str))?;102 }103 104 let style = ls_colors77- .style_for_path(path)105+ .style_for_path_with_metadata(path, entry.metadata())106 .map(Style::to_ansi_term_style)107 .unwrap_or_default();108 write!(stdout, "{}", style.paint(&path_str[offset..]))?;109 110+ print_trailing_slash(111+ stdout,112+ entry,113+ config,114+ ls_colors.style_for_indicator(Indicator::Directory),115+ )?;116+117 if config.null_separator {118 write!(stdout, "\0")?;119 } else {120 writeln!(stdout)?;4 unmodified lines125 126 // TODO: this function is performance critical and can probably be optimized127 fn print_entry_uncolorized_base<W: Write>(128 stdout: &mut W,94- path: &Path,129+ entry: &DirEntry,130 config: &Config,131 ) -> io::Result<()> {132 let separator = if config.null_separator { "\0" } else { "\n" };133+ let path = stripped_path(entry, config);134 135 let mut path_string = path.to_string_lossy();136 if let Some(ref separator) = config.path_separator {137 *path_string.to_mut() = replace_path_separator(&path_string, separator);138 }103- write!(stdout, "{}{}", path_string, separator)139+ write!(stdout, "{}", path_string)?;140+ print_trailing_slash(stdout, entry, config, None)?;141+ write!(stdout, "{}", separator)142 }143 144 #[cfg(not(unix))]145 fn print_entry_uncolorized<W: Write>(146 stdout: &mut W,109- path: &Path,147+ entry: &DirEntry,148 config: &Config,149 ) -> io::Result<()> {112- print_entry_uncolorized_base(stdout, path, config)150+ print_entry_uncolorized_base(stdout, entry, config)151 }152 153 #[cfg(unix)]154 fn print_entry_uncolorized<W: Write>(155 stdout: &mut W,118- path: &Path,156+ entry: &DirEntry,157 config: &Config,158 ) -> io::Result<()> {159 use std::os::unix::ffi::OsStrExt;160 161 if config.interactive_terminal || config.path_separator.is_some() {162 // Fall back to the base implementation125- print_entry_uncolorized_base(stdout, path, config)163+ print_entry_uncolorized_base(stdout, entry, config)164 } else {165 // Print path as raw bytes, allowing invalid UTF-8 filenames to be passed to other processes166 let separator = if config.null_separator { b"\0" } else { b"\n" };129- stdout.write_all(path.as_os_str().as_bytes())?;167+ stdout.write_all(stripped_path(entry, config).as_os_str().as_bytes())?;168+ print_trailing_slash(stdout, entry, config, None)?;169 stdout.write_all(separator)170 }171 }modified:src/walk.rs+10 added-67 removed
1 use std::ffi::OsStr;2-use std::fs::{FileType, Metadata};2 use std::io;3 use std::mem;5-use std::path::{Path, PathBuf};4+use std::path::PathBuf;5 use std::sync::atomic::{AtomicBool, Ordering};6 use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};7 use std::sync::{Arc, Mutex};8 use std::thread;2 unmodified lines11 12 use anyhow::{anyhow, Result};13 use ignore::overrides::OverrideBuilder;14 use ignore::{self, WalkBuilder};16-use once_cell::unsync::OnceCell;15 use regex::bytes::Regex;16 17 use crate::config::Config;18+use crate::dir_entry::DirEntry;19 use crate::error::print_error;20 use crate::exec;21 use crate::exit_codes::{merge_exitcodes, ExitCode};22 use crate::filesystem;11 unmodified lines34 }35 36 /// The Worker threads can result in a valid entry having PathBuf or an error.37 pub enum WorkerResult {39- Entry(PathBuf),38+ Entry(DirEntry),39 Error(ignore::Error),40 }41 42 /// Maximum size of the output buffer before flushing results to the console136 unmodified lines179 mode: ReceiverMode,180 /// The deadline to switch to streaming mode.181 deadline: Instant,182 /// The buffer of quickly received paths.184- buffer: Vec<PathBuf>,183+ buffer: Vec<DirEntry>,184 /// Result count.185 num_results: usize,186 }187 52 unmodified lines240 241 /// Wait for a result or state change.242 fn poll(&mut self) -> Result<(), ExitCode> {243 match self.recv() {245- Ok(WorkerResult::Entry(path)) => {244+ Ok(WorkerResult::Entry(dir_entry)) => {245 if self.config.quiet {246 return Err(ExitCode::HasResults(true));247 }248 249 match self.mode {250 ReceiverMode::Buffering => {252- self.buffer.push(path);251+ self.buffer.push(dir_entry);252 if self.buffer.len() > MAX_BUFFER_LENGTH {253 self.stream()?;254 }255 }256 ReceiverMode::Streaming => {258- self.print(&path)?;257+ self.print(&dir_entry)?;258 self.flush()?;259 }260 }261 20 unmodified lines282 Ok(())283 }284 285 /// Output a path.287- fn print(&mut self, path: &Path) -> Result<(), ExitCode> {288- output::print_entry(&mut self.stdout, path, &self.config);286+ fn print(&mut self, entry: &DirEntry) -> Result<(), ExitCode> {287+ output::print_entry(&mut self.stdout, entry, &self.config);288 289 if self.interrupt_flag.load(Ordering::Relaxed) {290 // Ignore any errors on flush, because we're about to exit anyway291 let _ = self.flush();102 unmodified lines394 }395 })396 }397 399-enum DirEntryInner {400- Normal(ignore::DirEntry),401- BrokenSymlink(PathBuf),402-}403-404-pub struct DirEntry {405- inner: DirEntryInner,406- metadata: OnceCell<Option<Metadata>>,407-}408-409-impl DirEntry {410- fn normal(e: ignore::DirEntry) -> Self {411- Self {412- inner: DirEntryInner::Normal(e),413- metadata: OnceCell::new(),414- }415- }416-417- fn broken_symlink(path: PathBuf) -> Self {418- Self {419- inner: DirEntryInner::BrokenSymlink(path),420- metadata: OnceCell::new(),421- }422- }423-424- pub fn path(&self) -> &Path {425- match &self.inner {426- DirEntryInner::Normal(e) => e.path(),427- DirEntryInner::BrokenSymlink(pathbuf) => pathbuf.as_path(),428- }429- }430-431- pub fn file_type(&self) -> Option<FileType> {432- match &self.inner {433- DirEntryInner::Normal(e) => e.file_type(),434- DirEntryInner::BrokenSymlink(_) => self.metadata().map(|m| m.file_type()),435- }436- }437-438- pub fn metadata(&self) -> Option<&Metadata> {439- self.metadata440- .get_or_init(|| match &self.inner {441- DirEntryInner::Normal(e) => e.metadata().ok(),442- DirEntryInner::BrokenSymlink(path) => path.symlink_metadata().ok(),443- })444- .as_ref()445- }446-447- pub fn depth(&self) -> Option<usize> {448- match &self.inner {449- DirEntryInner::Normal(e) => Some(e.depth()),450- DirEntryInner::BrokenSymlink(_) => None,451- }452- }453-}454-398 fn spawn_senders(399 config: &Arc<Config>,400 quit_flag: &Arc<AtomicBool>,401 pattern: Arc<Regex>,142 unmodified lines544 return ignore::WalkState::Continue;545 }546 }547 605- let send_result = tx_thread.send(WorkerResult::Entry(entry_path.to_owned()));548+ let send_result = tx_thread.send(WorkerResult::Entry(entry));549 550 if send_result.is_err() {551 return ignore::WalkState::Quit;552 }10 unmodified linesmodified:tests/tests.rs+97 added-97 removed
70 unmodified lines71 ./one/b.foo72 ./one/two/c.foo73 ./one/two/C.Foo274 ./one/two/three/d.foo75- ./one/two/three/directory_foo",75+ ./one/two/three/directory_foo/",76 );77 }78 79 /// Test each pattern type with an empty pattern.1 unmodified line81 fn test_empty_pattern() {82 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);83 let expected = "./a.foo84 ./e1 e285- ./one85+ ./one/86 ./one/b.foo87- ./one/two87+ ./one/two/88 ./one/two/c.foo89 ./one/two/C.Foo290- ./one/two/three90+ ./one/two/three/91 ./one/two/three/d.foo92- ./one/two/three/directory_foo92+ ./one/two/three/directory_foo/93 ./symlink";94 95 te.assert_output(&["--regex"], expected);96 te.assert_output(&["--fixed-strings"], expected);73 unmodified lines170 "one/b.foo171 one/two/c.foo172 one/two/C.Foo2173 one/two/three/d.foo174- one/two/three/directory_foo",174+ one/two/three/directory_foo/",175 );176 177 te.assert_output(178 &["foo", "one/two/three"],179 "one/two/three/d.foo180- one/two/three/directory_foo",180+ one/two/three/directory_foo/",181 );182 183 te.assert_output_subdirectory(184- "one/two",184+ "one/two/",185 &["foo", "../../"],186 "../../a.foo187 ../../one/b.foo188 ../../one/two/c.foo189 ../../one/two/C.Foo2190 ../../one/two/three/d.foo191- ../../one/two/three/directory_foo",191+ ../../one/two/three/directory_foo/",192 );193 194 te.assert_output_subdirectory(195 "one/two/three",196 &["", ".."],197 "../c.foo198 ../C.Foo2199- ../three199+ ../three/200 ../three/d.foo201- ../three/directory_foo",201+ ../three/directory_foo/",202 );203 }204 205 /// Regex searches180 unmodified lines386 "--full-path",387 &format!("^{prefix}.*three.*foo$", prefix = prefix),388 ],389 "./one/two/three/d.foo390- ./one/two/three/directory_foo",390+ ./one/two/three/directory_foo/",391 );392 }393 394 /// Hidden files (--hidden)8 unmodified lines403 ./one/b.foo404 ./one/two/c.foo405 ./one/two/C.Foo2406 ./one/two/three/d.foo407- ./one/two/three/directory_foo",407+ ./one/two/three/directory_foo/",408 );409 }410 411 /// Hidden file attribute on Windows31 unmodified lines443 ./one/b.foo444 ./one/two/c.foo445 ./one/two/C.Foo2446 ./one/two/three/d.foo447- ./one/two/three/directory_foo",447+ ./one/two/three/directory_foo/",448 );449 450 te.assert_output(451 &["--hidden", "--no-ignore", "foo"],4 unmodified lines456 ./one/b.foo457 ./one/two/c.foo458 ./one/two/C.Foo2459 ./one/two/three/d.foo460- ./one/two/three/directory_foo",460+ ./one/two/three/directory_foo/",461 );462 }463 464 /// .gitignore and .fdignore144 unmodified lines609 ./one/b.foo610 ./one/two/c.foo611 ./one/two/C.Foo2612 ./one/two/three/d.foo613- ./one/two/three/directory_foo",613+ ./one/two/three/directory_foo/",614 );615 }616 617 /// Test that --no-ignore-vcs still respects .fdignored in parent directory45 unmodified lines663 ./one/b.foo664 ./one/two/c.foo665 ./one/two/C.Foo2666 ./one/two/three/d.foo667- ./one/two/three/directory_foo",667+ ./one/two/three/directory_foo/",668 );669 }670 671 /// Symlinks (--follow)90 unmodified lines762 ./one/b.fooNULL763 ./one/two/C.Foo2NULL764 ./one/two/c.fooNULL765 ./one/two/three/d.fooNULL766- ./one/two/three/directory_fooNULL",766+ ./one/two/three/directory_foo/NULL",767 );768 }769 770 /// Maximum depth (--max-depth)4 unmodified lines775 te.assert_output(776 &["--max-depth", "3"],777 "./a.foo778 ./e1 e2779- ./one779+ ./one/780 ./one/b.foo781- ./one/two781+ ./one/two/782 ./one/two/c.foo783 ./one/two/C.Foo2784- ./one/two/three784+ ./one/two/three/785 ./symlink",786 );787 788 te.assert_output(789 &["--max-depth", "2"],790 "./a.foo791 ./e1 e2792- ./one792+ ./one/793 ./one/b.foo794- ./one/two794+ ./one/two/795 ./symlink",796 );797 798 te.assert_output(799 &["--max-depth", "1"],800 "./a.foo801 ./e1 e2802- ./one802+ ./one/803 ./symlink",804 );805 }806 5 unmodified lines812 te.assert_output(813 &["--min-depth", "3"],814 "./one/two/c.foo815 ./one/two/C.Foo2816- ./one/two/three816+ ./one/two/three/817 ./one/two/three/d.foo818- ./one/two/three/directory_foo",818+ ./one/two/three/directory_foo/",819 );820 821 te.assert_output(822 &["--min-depth", "4"],823 "./one/two/three/d.foo824- ./one/two/three/directory_foo",824+ ./one/two/three/directory_foo/",825 );826 }827 828 /// Exact depth (--exact-depth)4 unmodified lines833 te.assert_output(834 &["--exact-depth", "3"],835 "./one/two/c.foo836 ./one/two/C.Foo2837- ./one/two/three",837+ ./one/two/three/",838 );839 }840 841 /// Pruning (--prune)11 unmodified lines853 let te = TestEnv::new(dirs, files);854 855 te.assert_output(856 &["foo"],857- "./foo857+ "./foo/858 ./foo/foo.file859 ./foo/bar/foo.file860 ./bar/foo.file861- ./bar/foo861+ ./bar/foo/862 ./bar/foo/foo.file863 ./baz/foo.file",864 );865 866 te.assert_output(867 &["--prune", "foo"],868- "./foo869- ./bar/foo868+ "./foo/869+ ./bar/foo/870 ./bar/foo.file871 ./baz/foo.file",872 );873 }7 unmodified lines881 &["--absolute-path"],882 &format!(883 "{abs_path}/a.foo884 {abs_path}/e1 e2885- {abs_path}/one885+ {abs_path}/one/886 {abs_path}/one/b.foo887- {abs_path}/one/two887+ {abs_path}/one/two/888 {abs_path}/one/two/c.foo889 {abs_path}/one/two/C.Foo2890- {abs_path}/one/two/three890+ {abs_path}/one/two/three/891 {abs_path}/one/two/three/d.foo892- {abs_path}/one/two/three/directory_foo892+ {abs_path}/one/two/three/directory_foo/893 {abs_path}/symlink",894 abs_path = &abs_path895 ),896 );5 unmodified lines902 {abs_path}/one/b.foo903 {abs_path}/one/two/c.foo904 {abs_path}/one/two/C.Foo2905 {abs_path}/one/two/three/d.foo906- {abs_path}/one/two/three/directory_foo",906+ {abs_path}/one/two/three/directory_foo/",907 abs_path = &abs_path908 ),909 );910 }10 unmodified lines921 {abs_path}/one/b.foo922 {abs_path}/one/two/c.foo923 {abs_path}/one/two/C.Foo2924 {abs_path}/one/two/three/d.foo925- {abs_path}/one/two/three/directory_foo",925+ {abs_path}/one/two/three/directory_foo/",926 abs_path = &abs_path927 ),928 );929 }11 unmodified lines941 {abs_path}/one/b.foo942 {abs_path}/one/two/c.foo943 {abs_path}/one/two/C.Foo2944 {abs_path}/one/two/three/d.foo945- {abs_path}/one/two/three/directory_foo",945+ {abs_path}/one/two/three/directory_foo/",946 abs_path = &abs_path947 ),948 );949 }16 unmodified lines966 te.assert_output(&["--type", "f", "e1"], "./e1 e2");967 968 te.assert_output(969 &["--type", "d"],970- "./one971- ./one/two972- ./one/two/three973- ./one/two/three/directory_foo",970+ "./one/971+ ./one/two/972+ ./one/two/three/973+ ./one/two/three/directory_foo/",974 );975 976 te.assert_output(977 &["--type", "d", "--type", "l"],978- "./one979- ./one/two980- ./one/two/three981- ./one/two/three/directory_foo978+ "./one/979+ ./one/two/980+ ./one/two/three/981+ ./one/two/three/directory_foo/982 ./symlink",983 );984 985 te.assert_output(&["--type", "l"], "./symlink");18 unmodified lines1004 1005 te.assert_output(1006 &["--type", "executable", "--type", "directory"],1007 "./executable-file.sh1008- ./one1009- ./one/two1010- ./one/two/three1011- ./one/two/three/directory_foo",1008+ ./one/1009+ ./one/two/1010+ ./one/two/three/1011+ ./one/two/three/directory_foo/",1012 );1013 }1014 1015 /// Test `--type empty`8 unmodified lines1024 1025 te.assert_output(1026 &["--type", "empty"],1027 "./0_bytes.foo1028- ./dir_empty",1028+ ./dir_empty/",1029 );1030 1031 te.assert_output(1032 &["--type", "empty", "--type", "file", "--type", "directory"],1033 "./0_bytes.foo1034- ./dir_empty",1034+ ./dir_empty/",1035 );1036 1037 te.assert_output(&["--type", "empty", "--type", "file"], "./0_bytes.foo");1038 1039- te.assert_output(&["--type", "empty", "--type", "directory"], "./dir_empty");1039+ te.assert_output(&["--type", "empty", "--type", "directory"], "./dir_empty/");1040 }1041 1042 /// File extension (--extension)1043 #[test]62 unmodified lines1106 1107 te.assert_output(1108 &["^[^.]+$"],1109 "./aa1110- ./one1110+ ./one/1111 ./one/bb1112- ./one/two1113- ./one/two/three1112+ ./one/two/1113+ ./one/two/three/1114 ./one/two/three/d1115- ./one/two/three/directory_foo1115+ ./one/two/three/directory_foo/1116 ./symlink",1117 );1118 1119 te.assert_output(31 unmodified lines1151 &format!(1152 "{dir}/a.foo1153 {dir}/broken_symlink1154 {dir}/e1 e21155- {dir}/one1155+ {dir}/one/1156 {dir}/one/b.foo1157- {dir}/one/two1157+ {dir}/one/two/1158 {dir}/one/two/c.foo1159 {dir}/one/two/C.Foo21160- {dir}/one/two/three1160+ {dir}/one/two/three/1161 {dir}/one/two/three/d.foo1162- {dir}/one/two/three/directory_foo1162+ {dir}/one/two/three/directory_foo/1163 {dir}/symlink",1164 dir = &parent_parent1165 ),1166 );10 unmodified lines1177 &["--absolute-path"],1178 &format!(1179 "{abs_path}/{expected_path}/c.foo1180 {abs_path}/{expected_path}/C.Foo21181- {abs_path}/{expected_path}/three1181+ {abs_path}/{expected_path}/three/1182 {abs_path}/{expected_path}/three/d.foo1183- {abs_path}/{expected_path}/three/directory_foo",1183+ {abs_path}/{expected_path}/three/directory_foo/",1184 abs_path = &abs_path,1185 expected_path = expected_path1186 ),1187 );7 unmodified lines1195 &["", &format!("{abs_path}/symlink", abs_path = abs_path)],1196 &format!(1197 "{abs_path}/symlink/c.foo1198 {abs_path}/symlink/C.Foo21199- {abs_path}/symlink/three1199+ {abs_path}/symlink/three/1200 {abs_path}/symlink/three/d.foo1201- {abs_path}/symlink/three/directory_foo",1201+ {abs_path}/symlink/three/directory_foo/",1202 abs_path = &abs_path1203 ),1204 );1205 }13 unmodified lines1219 "--full-path",1220 &format!("^{prefix}.*three", prefix = prefix),1221 ],1222 &format!(1223- "{abs_path}/{expected_path}/three1223+ "{abs_path}/{expected_path}/three/1224 {abs_path}/{expected_path}/three/d.foo1225- {abs_path}/{expected_path}/three/directory_foo",1225+ {abs_path}/{expected_path}/three/directory_foo/",1226 abs_path = &abs_path,1227 expected_path = expected_path1228 ),1229 );10 unmodified lines1240 &format!("^{prefix}.*symlink.*three", prefix = prefix),1241 &format!("{abs_path}/symlink", abs_path = abs_path),1242 ],1243 &format!(1244- "{abs_path}/symlink/three1244+ "{abs_path}/symlink/three/1245 {abs_path}/symlink/three/d.foo1246- {abs_path}/symlink/three/directory_foo",1246+ {abs_path}/symlink/three/directory_foo/",1247 abs_path = &abs_path1248 ),1249 );1250 }3 unmodified lines1254 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1255 1256 te.assert_output(1257 &["--exclude", "*.foo"],1258- "./one1259- ./one/two1258+ "./one/1259+ ./one/two/1260 ./one/two/C.Foo21261- ./one/two/three1262- ./one/two/three/directory_foo1261+ ./one/two/three/1262+ ./one/two/three/directory_foo/1263 ./e1 e21264 ./symlink",1265 );1266 1267 te.assert_output(1268 &["--exclude", "*.foo", "--exclude", "*.Foo2"],1269- "./one1270- ./one/two1271- ./one/two/three1272- ./one/two/three/directory_foo1269+ "./one/1270+ ./one/two/1271+ ./one/two/three/1272+ ./one/two/three/directory_foo/1273 ./e1 e21274 ./symlink",1275 );1276 1277 te.assert_output(1278 &["--exclude", "*.foo", "--exclude", "*.Foo2", "foo"],1279- "./one/two/three/directory_foo",1279+ "./one/two/three/directory_foo/",1280 );1281 1282 te.assert_output(1283- &["--exclude", "one/two", "foo"],1283+ &["--exclude", "one/two/", "foo"],1284 "./a.foo1285 ./one/b.foo",1286 );1287 1288 te.assert_output(1289 &["--exclude", "one/**/*.foo"],1290 "./a.foo1291 ./e1 e21292- ./one1293- ./one/two1292+ ./one/1293+ ./one/two/1294 ./one/two/C.Foo21295- ./one/two/three1296- ./one/two/three/directory_foo1295+ ./one/two/three/1296+ ./one/two/three/directory_foo/1297 ./symlink",1298 );1299 }1300 564 unmodified lines1865 "one=b.foo1866 one=two=c.foo1867 one=two=C.Foo21868 one=two=three=d.foo1869- one=two=three=directory_foo",1869+ one=two=three=directory_foo=",1870 );1871 }1872 1873 #[test]2 unmodified lines1876 1877 te.assert_output(1878 &["--base-directory", "one"],1879 "./b.foo1880- ./two1880+ ./two/1881 ./two/c.foo1882 ./two/C.Foo21883- ./two/three1883+ ./two/three/1884 ./two/three/d.foo1885- ./two/three/directory_foo",1885+ ./two/three/directory_foo/",1886 );1887 1888 te.assert_output(1889- &["--base-directory", "one/two", "foo"],1889+ &["--base-directory", "one/two/", "foo"],1890 "./c.foo1891 ./C.Foo21892 ./three/d.foo1893- ./three/directory_foo",1893+ ./three/directory_foo/",1894 );1895 1896 // Explicit root path1897 te.assert_output(1898 &["--base-directory", "one", "foo", "two"],1899 "two/c.foo1900 two/C.Foo21901 two/three/d.foo1902- two/three/directory_foo",1902+ two/three/directory_foo/",1903 );1904 1905 // Ignore base directory when absolute path is used1906 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);1907- let abs_base_dir = &format!("{abs_path}/one/two", abs_path = &abs_path);1907+ let abs_base_dir = &format!("{abs_path}/one/two/", abs_path = &abs_path);1908 te.assert_output(1909 &["--base-directory", abs_base_dir, "foo", &abs_path],1910 &format!(1911 "{abs_path}/a.foo1912 {abs_path}/one/b.foo1913 {abs_path}/one/two/c.foo1914 {abs_path}/one/two/C.Foo21915 {abs_path}/one/two/three/d.foo1916- {abs_path}/one/two/three/directory_foo",1916+ {abs_path}/one/two/three/directory_foo/",1917 abs_path = &abs_path1918 ),1919 );1920 }147 unmodified lines2068 te.assert_output(2069 &["--strip-cwd-prefix", "."],2070 "a.foo2071 e1 e22072- one2072+ one/2073 one/b.foo2074- one/two2074+ one/two/2075 one/two/c.foo2076 one/two/C.Foo22077- one/two/three2077+ one/two/three/2078 one/two/three/d.foo2079- one/two/three/directory_foo2079+ one/two/three/directory_foo/2080 symlink",2081 );2082 }modified:CHANGELOG.md+1 added
12 unmodified lines13 14 ## Changes15 16 - Changed `-u` flag to be equivalent to `-HI`. Multiple `-u` flags still allowed but do nothing, see #840 (@jacksontheel)17+- Directories are now printed with an additional path separator at the end: `foo/bar/`, see #436 and #812 (@yyogo)18 19 ## Other20 21 - Added installation instructions for RHEL8, see #989 (@ethsol)572 unmodified lines