mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-04-19 09:02:15 +02:00
ripgrep: remove workaround for std bug
This commit undoes a work-around for a bug in Rust's standard library that prevented correct file type detection on Windows in OneDrive directories. We remove the work-around because we are moving to a latest-stable Rust version policy, which has included this fix for a while now. ref #705, https://github.com/rust-lang/rust/issues/46484
This commit is contained in:
parent
95a4f15916
commit
1529ce3341
@ -216,19 +216,6 @@ impl DirEntryInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if this entry points to a directory.
|
/// Returns true if and only if this entry points to a directory.
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn is_dir(&self) -> bool {
|
|
||||||
self.metadata().map(|md| metadata_is_dir(&md)).unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if this entry points to a directory.
|
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn is_dir(&self) -> bool {
|
fn is_dir(&self) -> bool {
|
||||||
self.file_type().map(|ft| ft.is_dir()).unwrap_or(false)
|
self.file_type().map(|ft| ft.is_dir()).unwrap_or(false)
|
||||||
}
|
}
|
||||||
@ -253,10 +240,6 @@ struct DirEntryRaw {
|
|||||||
ino: u64,
|
ino: u64,
|
||||||
/// The underlying metadata (Windows only). We store this on Windows
|
/// The underlying metadata (Windows only). We store this on Windows
|
||||||
/// because this comes for free while reading a directory.
|
/// because this comes for free while reading a directory.
|
||||||
///
|
|
||||||
/// We use this to determine whether an entry is a directory or not, which
|
|
||||||
/// works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
metadata: fs::Metadata,
|
metadata: fs::Metadata,
|
||||||
}
|
}
|
||||||
@ -509,7 +492,7 @@ impl WalkBuilder {
|
|||||||
(p.to_path_buf(), None)
|
(p.to_path_buf(), None)
|
||||||
} else {
|
} else {
|
||||||
let mut wd = WalkDir::new(p);
|
let mut wd = WalkDir::new(p);
|
||||||
wd = wd.follow_links(follow_links || path_is_file(p));
|
wd = wd.follow_links(follow_links || p.is_file());
|
||||||
if let Some(max_depth) = max_depth {
|
if let Some(max_depth) = max_depth {
|
||||||
wd = wd.max_depth(max_depth);
|
wd = wd.max_depth(max_depth);
|
||||||
}
|
}
|
||||||
@ -776,7 +759,7 @@ impl Walk {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_dir = walkdir_entry_is_dir(ent);
|
let is_dir = ent.file_type().is_dir();
|
||||||
let max_size = self.max_filesize;
|
let max_size = self.max_filesize;
|
||||||
let should_skip_path = skip_path(&self.ig, ent.path(), is_dir);
|
let should_skip_path = skip_path(&self.ig, ent.path(), is_dir);
|
||||||
let should_skip_filesize = if !is_dir && max_size.is_some() {
|
let should_skip_filesize = if !is_dir && max_size.is_some() {
|
||||||
@ -805,7 +788,7 @@ impl Iterator for Walk {
|
|||||||
}
|
}
|
||||||
Some((path, Some(it))) => {
|
Some((path, Some(it))) => {
|
||||||
self.it = Some(it);
|
self.it = Some(it);
|
||||||
if path_is_dir(&path) {
|
if path.is_dir() {
|
||||||
let (ig, err) = self.ig_root.add_parents(path);
|
let (ig, err) = self.ig_root.add_parents(path);
|
||||||
self.ig = ig;
|
self.ig = ig;
|
||||||
if let Some(err) = err {
|
if let Some(err) = err {
|
||||||
@ -895,7 +878,7 @@ impl Iterator for WalkEventIter {
|
|||||||
None => None,
|
None => None,
|
||||||
Some(Err(err)) => Some(Err(err)),
|
Some(Err(err)) => Some(Err(err)),
|
||||||
Some(Ok(dent)) => {
|
Some(Ok(dent)) => {
|
||||||
if walkdir_entry_is_dir(&dent) {
|
if dent.file_type().is_dir() {
|
||||||
self.depth += 1;
|
self.depth += 1;
|
||||||
Some(Ok(WalkEvent::Dir(dent)))
|
Some(Ok(WalkEvent::Dir(dent)))
|
||||||
} else {
|
} else {
|
||||||
@ -1434,62 +1417,6 @@ fn skip_path(ig: &Ignore, path: &Path, is_dir: bool) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if this path points to a directory.
|
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn path_is_dir(path: &Path) -> bool {
|
|
||||||
fs::metadata(path).map(|md| metadata_is_dir(&md)).unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if this entry points to a directory.
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn path_is_dir(path: &Path) -> bool {
|
|
||||||
path.is_dir()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if this path points to a file.
|
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn path_is_file(path: &Path) -> bool {
|
|
||||||
!path_is_dir(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if this entry points to a directory.
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn path_is_file(path: &Path) -> bool {
|
|
||||||
path.is_file()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if the given walkdir entry points to a directory.
|
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn walkdir_entry_is_dir(dent: &walkdir::DirEntry) -> bool {
|
|
||||||
dent.metadata().map(|md| metadata_is_dir(&md)).unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if the given walkdir entry points to a directory.
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn walkdir_entry_is_dir(dent: &walkdir::DirEntry) -> bool {
|
|
||||||
dent.file_type().is_dir()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if the given metadata points to a directory.
|
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn metadata_is_dir(md: &fs::Metadata) -> bool {
|
|
||||||
use std::os::windows::fs::MetadataExt;
|
|
||||||
use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
md.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
|
@ -172,36 +172,11 @@ impl Subject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if this subject points to a directory.
|
/// Returns true if and only if this subject points to a directory.
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn is_dir(&self) -> bool {
|
|
||||||
use std::os::windows::fs::MetadataExt;
|
|
||||||
use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
|
|
||||||
self.dent.metadata().map(|md| {
|
|
||||||
md.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0
|
|
||||||
}).unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if this subject points to a directory.
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn is_dir(&self) -> bool {
|
fn is_dir(&self) -> bool {
|
||||||
self.dent.file_type().map_or(false, |ft| ft.is_dir())
|
self.dent.file_type().map_or(false, |ft| ft.is_dir())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if this subject points to a file.
|
/// Returns true if and only if this subject points to a file.
|
||||||
///
|
|
||||||
/// This works around a bug in Rust's standard library:
|
|
||||||
/// https://github.com/rust-lang/rust/issues/46484
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn is_file(&self) -> bool {
|
|
||||||
!self.is_dir()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if this subject points to a file.
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn is_file(&self) -> bool {
|
fn is_file(&self) -> bool {
|
||||||
self.dent.file_type().map_or(false, |ft| ft.is_file())
|
self.dent.file_type().map_or(false, |ft| ft.is_file())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user