Skip to content
Myr

Throw an error if root directory is non-existent, fixes #39

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 24070b0 · Browse files · 1 file+16 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−7 removed

  • other:+16 added−7 removed

1 file+16 added−7 removed

modified:src/main.rs+16 added-7 removed
103 unmodified lines
104 for component in entry.components() {105 let comp_str = match component {106 Component::Normal(p) => p.to_string_lossy(),107 Component::ParentDir => Cow::from(PARENT_DIR),108 _ => error("Unexpected path component")108 _ => error("Error: unexpected path component")109 };110111 component_path.push(Path::new(comp_str.deref()));112
64 unmodified lines
177178 for entry in walker {179 let path_rel_buf = match fshelper::path_relative_from(entry.path(), base) {180 Some(p) => p,181 None => error("Could not get relative path for directory entry.")181 None => error("Error: could not get relative path for directory entry.")182 };183 let path_rel = path_rel_buf.as_path();184185 let search_str_o =
70 unmodified lines
256257 // Get the current working directory258 let current_dir_buf = match env::current_dir() {259 Ok(cd) => cd,260 Err(_) => error("Could not get current directory!")260 Err(_) => error("Error: could not get current directory!")261 };262 let current_dir = current_dir_buf.as_path();263264 // Get the root directory for the search265 let root_dir_buf = matches.value_of("path")266 .and_then(|r| fs::canonicalize(r).ok())267 .unwrap_or_else(|| current_dir_buf.clone());265 let root_dir_buf = if let Some(rd) = matches.value_of("path") {266 fs::canonicalize(rd).unwrap_or_else(267 |_| error(&format!("Error: could not find directory '{}'", rd))268 )269 } else {270 current_dir_buf.clone()271 };272273 if !root_dir_buf.is_dir() {274 error(&format!("Error: '{}' is not a directory", root_dir_buf.to_string_lossy()));275 }276277 let root_dir = root_dir_buf.as_path();278279 // The search will be case-sensitive if the command line flag is set or280 // if the pattern has an uppercase character (smart case).
21 unmodified lines
302 ignore_hidden: !matches.is_present("hidden"),303 read_ignore: !matches.is_present("no-ignore"),304 follow_links: matches.is_present("follow"),305 max_depth: matches.value_of("depth")297 .and_then(|ds| usize::from_str_radix(&ds, 10).ok()),306 .and_then(|ds| usize::from_str_radix(ds, 10).ok()),307 path_display: if matches.is_present("absolute-path") {308 PathDisplay::Absolute309 } else {310 PathDisplay::Relative
17 unmodified lines