Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/walkdir.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-02-21 03:05:31 +0300
committerAndrew Gallant <jamslam@gmail.com>2018-02-21 03:24:05 +0300
commite3223962fec481b72a264ab7f41846b47483354b (patch)
tree1e97dcd4d7e0c5b2746bd14557e3adf18d6fabdd
parent44a5dfe6f7a64ec2d8685e8d2b2409a55b7902d5 (diff)
compile: clean up cfgs
In some cases, we were relying on things like "not(unix)" to mean "windows" or "not(windows)" to mean "unix". Instead, we should split this in three cases: unix, windows or not(unix or windows).
-rw-r--r--src/lib.rs50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3a1df69..423ca1d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -631,7 +631,8 @@ pub struct DirEntry {
/// The underlying inode number (Unix only).
#[cfg(unix)]
ino: u64,
- /// The underlying metadata (Windows only).
+ /// The underlying metadata (Windows only). We store this on Windows
+ /// 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:
@@ -1057,7 +1058,7 @@ impl DirEntry {
self.ty.is_dir()
}
- #[cfg(not(unix))]
+ #[cfg(windows)]
fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> {
let path = ent.path();
let ty = ent.file_type().map_err(|err| {
@@ -1091,7 +1092,22 @@ impl DirEntry {
})
}
- #[cfg(not(unix))]
+ #[cfg(not(any(unix, windows)))]
+ fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> {
+ use std::os::unix::fs::DirEntryExt;
+
+ let ty = ent.file_type().map_err(|err| {
+ Error::from_path(depth, ent.path(), err)
+ })?;
+ Ok(DirEntry {
+ path: ent.path(),
+ ty: ty,
+ follow_link: false,
+ depth: depth,
+ })
+ }
+
+ #[cfg(windows)]
fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> {
let md = fs::metadata(&pb).map_err(|err| {
Error::from_path(depth, pb.clone(), err)
@@ -1120,10 +1136,25 @@ impl DirEntry {
ino: md.ino(),
})
}
+
+ #[cfg(not(any(unix, windows)))]
+ fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> {
+ use std::os::unix::fs::MetadataExt;
+
+ let md = fs::metadata(&pb).map_err(|err| {
+ Error::from_path(depth, pb.clone(), err)
+ })?;
+ Ok(DirEntry {
+ path: pb,
+ ty: md.file_type(),
+ follow_link: true,
+ depth: depth,
+ })
+ }
}
impl Clone for DirEntry {
- #[cfg(not(unix))]
+ #[cfg(windows)]
fn clone(&self) -> DirEntry {
DirEntry {
path: self.path.clone(),
@@ -1144,6 +1175,17 @@ impl Clone for DirEntry {
ino: self.ino,
}
}
+
+ #[cfg(not(any(unix, windows)))]
+ fn clone(&self) -> DirEntry {
+ DirEntry {
+ path: self.path.clone(),
+ ty: self.ty,
+ follow_link: self.follow_link,
+ depth: self.depth,
+ ino: self.ino,
+ }
+ }
}
impl fmt::Debug for DirEntry {