diff --git a/src/tools/fs.rs b/src/tools/fs.rs
index 8ab33477..447583b9 100644
--- a/src/tools/fs.rs
+++ b/src/tools/fs.rs
@@ -2,7 +2,7 @@
use std::borrow::{Borrow, BorrowMut};
use std::ops::{Deref, DerefMut};
-use std::os::unix::io::RawFd;
+use std::os::unix::io::{AsRawFd, RawFd};
use failure::Error;
use nix::dir;
@@ -72,13 +72,17 @@ impl ReadDirEntry {
/// Wrapper over a pair of `nix::dir::Dir` and `nix::dir::Iter`, returned by `read_subdir()`.
pub struct ReadDir {
iter: Tied
>>,
+ dir_fd: RawFd,
}
impl Iterator for ReadDir {
- type Item = Result;
+ type Item = Result;
fn next(&mut self) -> Option {
- self.iter.next().map(|res| res.map_err(|e| Error::from(e)))
+ self.iter.next().map(|res| {
+ res.map(|entry| ReadDirEntry { entry, parent_fd: self.dir_fd })
+ .map_err(|e| Error::from(e))
+ })
}
}
@@ -89,10 +93,11 @@ pub fn read_subdir(dirfd: RawFd, path: &P) -> Result>>
});
- Ok(ReadDir { iter })
+ Ok(ReadDir { iter, dir_fd: fd })
}
/// Scan through a directory with a regular expression. This is simply a shortcut filtering the