Skip to content

Commit 1529ce3

Browse files
committed
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, rust-lang/rust#46484
1 parent 95a4f15 commit 1529ce3

File tree

2 files changed

+4
-102
lines changed

2 files changed

+4
-102
lines changed

ignore/src/walk.rs

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,6 @@ impl DirEntryInner {
216216
}
217217

218218
/// Returns true if and only if this entry points to a directory.
219-
///
220-
/// This works around a bug in Rust's standard library:
221-
/// https://github.com/rust-lang/rust/issues/46484
222-
#[cfg(windows)]
223-
fn is_dir(&self) -> bool {
224-
self.metadata().map(|md| metadata_is_dir(&md)).unwrap_or(false)
225-
}
226-
227-
/// Returns true if and only if this entry points to a directory.
228-
///
229-
/// This works around a bug in Rust's standard library:
230-
/// https://github.com/rust-lang/rust/issues/46484
231-
#[cfg(not(windows))]
232219
fn is_dir(&self) -> bool {
233220
self.file_type().map(|ft| ft.is_dir()).unwrap_or(false)
234221
}
@@ -253,10 +240,6 @@ struct DirEntryRaw {
253240
ino: u64,
254241
/// The underlying metadata (Windows only). We store this on Windows
255242
/// because this comes for free while reading a directory.
256-
///
257-
/// We use this to determine whether an entry is a directory or not, which
258-
/// works around a bug in Rust's standard library:
259-
/// https://github.com/rust-lang/rust/issues/46484
260243
#[cfg(windows)]
261244
metadata: fs::Metadata,
262245
}
@@ -509,7 +492,7 @@ impl WalkBuilder {
509492
(p.to_path_buf(), None)
510493
} else {
511494
let mut wd = WalkDir::new(p);
512-
wd = wd.follow_links(follow_links || path_is_file(p));
495+
wd = wd.follow_links(follow_links || p.is_file());
513496
if let Some(max_depth) = max_depth {
514497
wd = wd.max_depth(max_depth);
515498
}
@@ -776,7 +759,7 @@ impl Walk {
776759
return false;
777760
}
778761

779-
let is_dir = walkdir_entry_is_dir(ent);
762+
let is_dir = ent.file_type().is_dir();
780763
let max_size = self.max_filesize;
781764
let should_skip_path = skip_path(&self.ig, ent.path(), is_dir);
782765
let should_skip_filesize = if !is_dir && max_size.is_some() {
@@ -805,7 +788,7 @@ impl Iterator for Walk {
805788
}
806789
Some((path, Some(it))) => {
807790
self.it = Some(it);
808-
if path_is_dir(&path) {
791+
if path.is_dir() {
809792
let (ig, err) = self.ig_root.add_parents(path);
810793
self.ig = ig;
811794
if let Some(err) = err {
@@ -895,7 +878,7 @@ impl Iterator for WalkEventIter {
895878
None => None,
896879
Some(Err(err)) => Some(Err(err)),
897880
Some(Ok(dent)) => {
898-
if walkdir_entry_is_dir(&dent) {
881+
if dent.file_type().is_dir() {
899882
self.depth += 1;
900883
Some(Ok(WalkEvent::Dir(dent)))
901884
} else {
@@ -1434,62 +1417,6 @@ fn skip_path(ig: &Ignore, path: &Path, is_dir: bool) -> bool {
14341417
}
14351418
}
14361419

1437-
/// Returns true if and only if this path points to a directory.
1438-
///
1439-
/// This works around a bug in Rust's standard library:
1440-
/// https://github.com/rust-lang/rust/issues/46484
1441-
#[cfg(windows)]
1442-
fn path_is_dir(path: &Path) -> bool {
1443-
fs::metadata(path).map(|md| metadata_is_dir(&md)).unwrap_or(false)
1444-
}
1445-
1446-
/// Returns true if and only if this entry points to a directory.
1447-
#[cfg(not(windows))]
1448-
fn path_is_dir(path: &Path) -> bool {
1449-
path.is_dir()
1450-
}
1451-
1452-
/// Returns true if and only if this path points to a file.
1453-
///
1454-
/// This works around a bug in Rust's standard library:
1455-
/// https://github.com/rust-lang/rust/issues/46484
1456-
#[cfg(windows)]
1457-
fn path_is_file(path: &Path) -> bool {
1458-
!path_is_dir(path)
1459-
}
1460-
1461-
/// Returns true if and only if this entry points to a directory.
1462-
#[cfg(not(windows))]
1463-
fn path_is_file(path: &Path) -> bool {
1464-
path.is_file()
1465-
}
1466-
1467-
/// Returns true if and only if the given walkdir entry points to a directory.
1468-
///
1469-
/// This works around a bug in Rust's standard library:
1470-
/// https://github.com/rust-lang/rust/issues/46484
1471-
#[cfg(windows)]
1472-
fn walkdir_entry_is_dir(dent: &walkdir::DirEntry) -> bool {
1473-
dent.metadata().map(|md| metadata_is_dir(&md)).unwrap_or(false)
1474-
}
1475-
1476-
/// Returns true if and only if the given walkdir entry points to a directory.
1477-
#[cfg(not(windows))]
1478-
fn walkdir_entry_is_dir(dent: &walkdir::DirEntry) -> bool {
1479-
dent.file_type().is_dir()
1480-
}
1481-
1482-
/// Returns true if and only if the given metadata points to a directory.
1483-
///
1484-
/// This works around a bug in Rust's standard library:
1485-
/// https://github.com/rust-lang/rust/issues/46484
1486-
#[cfg(windows)]
1487-
fn metadata_is_dir(md: &fs::Metadata) -> bool {
1488-
use std::os::windows::fs::MetadataExt;
1489-
use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY;
1490-
md.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0
1491-
}
1492-
14931420
#[cfg(test)]
14941421
mod tests {
14951422
use std::fs::{self, File};

src/subject.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -172,36 +172,11 @@ impl Subject {
172172
}
173173

174174
/// Returns true if and only if this subject points to a directory.
175-
///
176-
/// This works around a bug in Rust's standard library:
177-
/// https://github.com/rust-lang/rust/issues/46484
178-
#[cfg(windows)]
179-
fn is_dir(&self) -> bool {
180-
use std::os::windows::fs::MetadataExt;
181-
use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY;
182-
183-
self.dent.metadata().map(|md| {
184-
md.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0
185-
}).unwrap_or(false)
186-
}
187-
188-
/// Returns true if and only if this subject points to a directory.
189-
#[cfg(not(windows))]
190175
fn is_dir(&self) -> bool {
191176
self.dent.file_type().map_or(false, |ft| ft.is_dir())
192177
}
193178

194179
/// Returns true if and only if this subject points to a file.
195-
///
196-
/// This works around a bug in Rust's standard library:
197-
/// https://github.com/rust-lang/rust/issues/46484
198-
#[cfg(windows)]
199-
fn is_file(&self) -> bool {
200-
!self.is_dir()
201-
}
202-
203-
/// Returns true if and only if this subject points to a file.
204-
#[cfg(not(windows))]
205180
fn is_file(&self) -> bool {
206181
self.dent.file_type().map_or(false, |ft| ft.is_file())
207182
}

0 commit comments

Comments
 (0)