mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #4508 from tertsdiepraam/pwd-minirefactor
`pwd`: small refactor of some match expressions
This commit is contained in:
commit
5967d66a20
1 changed files with 11 additions and 25 deletions
|
@ -15,10 +15,10 @@ use uucore::{format_usage, help_about, help_usage};
|
||||||
use uucore::display::println_verbatim;
|
use uucore::display::println_verbatim;
|
||||||
use uucore::error::{FromIo, UResult};
|
use uucore::error::{FromIo, UResult};
|
||||||
|
|
||||||
static ABOUT: &str = help_about!("pwd.md");
|
const ABOUT: &str = help_about!("pwd.md");
|
||||||
const USAGE: &str = help_usage!("pwd.md");
|
const USAGE: &str = help_usage!("pwd.md");
|
||||||
static OPT_LOGICAL: &str = "logical";
|
const OPT_LOGICAL: &str = "logical";
|
||||||
static OPT_PHYSICAL: &str = "physical";
|
const OPT_PHYSICAL: &str = "physical";
|
||||||
|
|
||||||
fn physical_path() -> io::Result<PathBuf> {
|
fn physical_path() -> io::Result<PathBuf> {
|
||||||
// std::env::current_dir() is a thin wrapper around libc::getcwd().
|
// std::env::current_dir() is a thin wrapper around libc::getcwd().
|
||||||
|
@ -84,36 +84,22 @@ fn logical_path() -> io::Result<PathBuf> {
|
||||||
{
|
{
|
||||||
use std::fs::metadata;
|
use std::fs::metadata;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
let path_info = match metadata(path) {
|
match (metadata(path), metadata(".")) {
|
||||||
Ok(info) => info,
|
(Ok(info1), Ok(info2)) => {
|
||||||
Err(_) => return false,
|
info1.dev() == info2.dev() && info1.ino() == info2.ino()
|
||||||
};
|
}
|
||||||
let real_info = match metadata(".") {
|
_ => false,
|
||||||
Ok(info) => info,
|
|
||||||
Err(_) => return false,
|
|
||||||
};
|
|
||||||
if path_info.dev() != real_info.dev() || path_info.ino() != real_info.ino() {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
{
|
{
|
||||||
use std::fs::canonicalize;
|
use std::fs::canonicalize;
|
||||||
let canon_path = match canonicalize(path) {
|
match (canonicalize(path), canonicalize(".")) {
|
||||||
Ok(path) => path,
|
(Ok(path1), Ok(path2)) => path1 == path2,
|
||||||
Err(_) => return false,
|
_ => false,
|
||||||
};
|
|
||||||
let real_path = match canonicalize(".") {
|
|
||||||
Ok(path) => path,
|
|
||||||
Err(_) => return false,
|
|
||||||
};
|
|
||||||
if canon_path != real_path {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match env::var_os("PWD").map(PathBuf::from) {
|
match env::var_os("PWD").map(PathBuf::from) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue