Skip to content
Myr

New implementation of broken-symlink handling

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

authored by sharkdp · committed by David Peter · parent bfc8c42 · Browse files · 2 files+56 added−8 removed
This commit

State

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

Diff stats

2 files+56 added−8 removed

  • other:+56 added−8 removed

2 files+56 added−8 removed

modified:src/fshelper/mod.rs+2 added-2 removed
11 unmodified lines
12#[cfg(any(unix, target_os = "redox"))]13use std::os::unix::fs::PermissionsExt;14use std::path::{Path, PathBuf};1516use ignore::DirEntry;16use crate::walk;1718pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {19 if path.is_absolute() {20 return Ok(path.to_path_buf());
33 unmodified lines
54pub fn is_executable(_: &fs::Metadata) -> bool {55 false56}5758pub fn is_empty(entry: &DirEntry) -> bool {58pub fn is_empty(entry: &walk::DirEntry) -> bool {59 if let Some(file_type) = entry.file_type() {60 if file_type.is_dir() {61 if let Ok(mut entries) = fs::read_dir(entry.path()) {62 entries.next().is_none()
12 unmodified lines
modified:src/walk.rs+54 added-6 removed
13 unmodified lines
1415use std::borrow::Cow;16use std::error::Error;17use std::ffi::OsStr;18use std::fs::{FileType, Metadata};19use std::io;19use std::path::PathBuf;20use std::path::{Path, PathBuf};21use std::process;22use std::sync::atomic::{AtomicBool, Ordering};23use std::sync::mpsc::{channel, Receiver, Sender};24use std::sync::{Arc, Mutex};
228 unmodified lines
253 }254 })255}256257pub enum DirEntry {258 Normal(ignore::DirEntry),259 BrokenSymlink(PathBuf),260}261262impl DirEntry {263 pub fn path(&self) -> &Path {264 match self {265 DirEntry::Normal(e) => e.path(),266 DirEntry::BrokenSymlink(pathbuf) => pathbuf.as_path(),267 }268 }269270 pub fn file_type(&self) -> Option<FileType> {271 match self {272 DirEntry::Normal(e) => e.file_type(),273 DirEntry::BrokenSymlink(pathbuf) => {274 pathbuf.symlink_metadata().map(|m| m.file_type()).ok()275 }276 }277 }278279 pub fn metadata(&self) -> Option<Metadata> {280 match self {281 DirEntry::Normal(e) => e.metadata().ok(),282 DirEntry::BrokenSymlink(_) => None,283 }284 }285}286287fn spawn_senders(288 config: &Arc<FdOptions>,289 wants_to_quit: &Arc<AtomicBool>,290 pattern: Arc<Regex>,
11 unmodified lines
302 return ignore::WalkState::Quit;303 }304305 let entry = match entry_o {275 Ok(e) => e,306 Ok(e) if e.depth() == 0 => {307 // Skip the root directory entry.308 return ignore::WalkState::Continue;309 }310 Ok(e) => DirEntry::Normal(e),311 Err(ignore::Error::WithPath {312 path,313 err: inner_err,314 }) => match inner_err.as_ref() {315 ignore::Error::Io(io_error) if io_error.kind() == io::ErrorKind::NotFound => {316 DirEntry::BrokenSymlink(path.to_owned())317 }318 _ => {319 tx_thread320 .send(WorkerResult::Error(ignore::Error::WithPath {321 path,322 err: inner_err,323 }))324 .unwrap();325 return ignore::WalkState::Continue;326 }327 },328 Err(err) => {329 tx_thread.send(WorkerResult::Error(err)).unwrap();330 return ignore::WalkState::Continue;331 }332 };333282 if entry.depth() == 0 {283 return ignore::WalkState::Continue;284 }285334 // Check the name first, since it doesn't require metadata335 let entry_path = entry.path();336337 let search_str: Cow<OsStr> = if config.search_full_path {
99 unmodified lines