mirror of
https://github.com/lsd-rs/lsd
synced 2025-03-05 07:27:20 +00:00
Handle correctly the special files metadata fetching
This commit is contained in:
parent
228a5bb11a
commit
823b04a258
2 changed files with 20 additions and 14 deletions
14
src/core.rs
14
src/core.rs
|
@ -24,11 +24,10 @@ impl<'a> Core<'a> {
|
|||
|
||||
if path.is_dir() {
|
||||
dirs.push(path);
|
||||
} else if path.is_file() {
|
||||
files.push(Meta::from(path));
|
||||
} else {
|
||||
let err = path.metadata().unwrap_err();
|
||||
println!("cannot access '{}': {}", path.display(), err);
|
||||
if let Some(meta) = Meta::from_path(path) {
|
||||
files.push(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,9 +73,10 @@ impl<'a> Core<'a> {
|
|||
|
||||
for entry in dir {
|
||||
if let Ok(entry) = entry {
|
||||
let meta = Meta::from(entry.path().as_path());
|
||||
if !meta.name.is_hidden() || self.options.display_all {
|
||||
metas.push(meta);
|
||||
if let Some(meta) = Meta::from_path(entry.path().as_path()) {
|
||||
if !meta.name.is_hidden() || self.options.display_all {
|
||||
metas.push(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,17 @@ pub struct Meta {
|
|||
pub symlink: Option<SymLink>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Path> for Meta {
|
||||
fn from(path: &Path) -> Self {
|
||||
let metadata;
|
||||
impl Meta {
|
||||
pub fn from_path(path: &Path) -> Option<Self> {
|
||||
let mut metadata = match path.metadata() {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
println!("cannot access '{}': {}", path.display(), err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
let file_type = FileType::from(&metadata);
|
||||
|
||||
if read_link(path).is_ok() {
|
||||
// If the file is a link, retrieve the metadata without following
|
||||
|
@ -42,9 +50,7 @@ impl<'a> From<&'a Path> for Meta {
|
|||
metadata = path.metadata().expect("failed to retrieve metadata");
|
||||
}
|
||||
|
||||
let file_type = FileType::from(&metadata);
|
||||
|
||||
Meta {
|
||||
Some(Meta {
|
||||
symlink: SymLink::from_path(&path),
|
||||
size: Size::from(&metadata),
|
||||
permissions: Permissions::from(&metadata),
|
||||
|
@ -52,6 +58,6 @@ impl<'a> From<&'a Path> for Meta {
|
|||
name: Name::new(&path, file_type),
|
||||
owner: Owner::from(&metadata),
|
||||
file_type,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue