Skip to content
Myr

Minor changes to improve readability

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

This patch makes minor changes to make the code a little easier to understand. For example, using the `?` operator in some fns that return an `Option` type.

authored by Josh Leeb-du Toit · committed by David Peter · parent cb1cfa1 · Browse files · 3 files+13 added−27 removed
This commit

State

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

Diff stats

3 files+13 added−27 removed

  • other:+13 added−27 removed

3 files+13 added−27 removed

modified:src/exec/command.rs+4 added-5 removed
27 unmodified lines
2829 let _ = stdout.lock().write_all(&output.stdout);30 let _ = stderr.lock().write_all(&output.stderr);31 }32 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {33 eprintln!("fd: execution error: command not found");34 }35 Err(why) => {33 if why.kind() == io::ErrorKind::NotFound {34 eprintln!("fd: execution error: command not found");35 } else {36 eprintln!("fd: execution error: {}", why);36 eprintln!("fd: execution error: {}", why);37 }37 }38 }39}
modified:src/fshelper/mod.rs+5 added-9 removed
15 unmodified lines
16use ignore::DirEntry;1718pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {19 if path.is_absolute() {20 Ok(path.to_path_buf())21 } else {22 let path = path.strip_prefix(".").unwrap_or(path);23 current_dir().map(|path_buf| path_buf.join(path))20 return Ok(path.to_path_buf());21 }2223 let path = path.strip_prefix(".").unwrap_or(path);24 current_dir().map(|path_buf| path_buf.join(path))25}2627pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {28 let path_buf = path_absolute_form(path)?;
12 unmodified lines
4142// Path::is_dir() is not guaranteed to be intuitively correct for "." and ".."43// See: https://github.com/rust-lang/rust/issues/4530244pub fn is_dir(path: &Path) -> bool {45 if path.file_name().is_some() {46 path.is_dir()47 } else {48 path.is_dir() && path.canonicalize().is_ok()49 }45 path.is_dir() && (path.file_name().is_some() || path.canonicalize().is_ok())46}4748#[cfg(any(unix, target_os = "redox"))]49pub fn is_executable(md: &fs::Metadata) -> bool {
25 unmodified lines
modified:src/internal.rs+4 added-13 removed
64 unmodified lines
65 if !SIZE_CAPTURES.is_match(s) {66 return None;67 }6869 let captures = match SIZE_CAPTURES.captures(s) {70 Some(cap) => cap,71 None => return None,72 };7369 let captures = SIZE_CAPTURES.captures(s)?;70 let limit_kind = captures.get(1).map_or("+", |m| m.as_str());71 let quantity = captures72 .get(2)73 .and_then(|v| v.as_str().parse::<u64>().ok())?;7476 let quantity = match captures.get(2) {77 None => return None,78 Some(v) => match v.as_str().parse::<u64>() {79 Ok(val) => val,80 _ => return None,81 },82 };8375 let multiplier = match &captures.get(3).map_or("b", |m| m.as_str()).to_lowercase()[..] {76 v if v.starts_with("ki") => KIBI,77 v if v.starts_with("k") => KILO,78 v if v.starts_with("mi") => MEBI,
393 unmodified lines