From 5e01a58b84d47b20d020d12c69799ec8db365274 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Wed, 28 Sep 2016 01:25:44 -0700 Subject: [PATCH] Fix DirEntry's metadata() method --- src/services/fs.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/services/fs.rs b/src/services/fs.rs index a01ae73..aa07220 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -73,14 +73,16 @@ pub struct OpenOptions { arch_handle: u64, } -pub struct ReadDir { +pub struct ReadDir<'a> { handle: Dir, root: Arc, + arch: &'a Archive, } -pub struct DirEntry { +pub struct DirEntry<'a> { entry: FS_DirectoryEntry, root: Arc, + arch: &'a Archive, } struct Dir(u32); @@ -282,14 +284,15 @@ impl OpenOptions { } } -impl Iterator for ReadDir { - type Item = Result; +impl<'a> Iterator for ReadDir<'a> { + type Item = Result, i32>; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option, i32>> { unsafe { let mut ret = DirEntry { entry: mem::zeroed(), root: self.root.clone(), + arch: self.arch, }; let mut entries_read = 0; let entry_count = 1; @@ -306,15 +309,13 @@ impl Iterator for ReadDir { } } -impl DirEntry { +impl<'a> DirEntry<'a> { pub fn path(&self) -> PathBuf { self.root.join(&self.file_name()) } - // Requiring the user to explicitly pass in the Archive here is pretty ugly, - // But I'm not sure of how else to do it right now. - pub fn metadata(&self, arch: &Archive) -> Result { - metadata(&arch, self.path()) + pub fn metadata(&self) -> Result { + metadata(self.arch, self.path()) } pub fn file_name(&self) -> OsString { @@ -412,7 +413,7 @@ pub fn rename(arch: &Archive, from: P, to: Q) -> Result<(), i32> } } -fn readdir(arch: &Archive, p: &Path) -> Result { +fn readdir<'a>(arch: &'a Archive, p: &Path) -> Result, i32> { unsafe { let mut handle = 0; let root = Arc::new(p.to_path_buf()); @@ -422,7 +423,7 @@ fn readdir(arch: &Archive, p: &Path) -> Result { if r < 0 { Err(r) } else { - Ok(ReadDir { handle: Dir(handle), root: root }) + Ok(ReadDir { handle: Dir(handle), root: root, arch: arch}) } } }