aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFenrir <[email protected]>2016-09-28 01:25:44 -0700
committerFenrir <[email protected]>2016-09-28 01:25:44 -0700
commit5e01a58b84d47b20d020d12c69799ec8db365274 (patch)
tree6f512f224f458a2d8a627415c2e91b755e72e2ca
parentAdd metadata struct and functions (diff)
downloadctru-rs-5e01a58b84d47b20d020d12c69799ec8db365274.tar.xz
ctru-rs-5e01a58b84d47b20d020d12c69799ec8db365274.zip
Fix DirEntry's metadata() method
-rw-r--r--src/services/fs.rs25
1 files 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<PathBuf>,
+ arch: &'a Archive,
}
-pub struct DirEntry {
+pub struct DirEntry<'a> {
entry: FS_DirectoryEntry,
root: Arc<PathBuf>,
+ arch: &'a Archive,
}
struct Dir(u32);
@@ -282,14 +284,15 @@ impl OpenOptions {
}
}
-impl Iterator for ReadDir {
- type Item = Result<DirEntry, i32>;
+impl<'a> Iterator for ReadDir<'a> {
+ type Item = Result<DirEntry<'a>, i32>;
- fn next(&mut self) -> Option<Result<DirEntry, i32>> {
+ fn next(&mut self) -> Option<Result<DirEntry<'a>, 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, i32> {
- metadata(&arch, self.path())
+ pub fn metadata(&self) -> Result<Metadata, i32> {
+ metadata(self.arch, self.path())
}
pub fn file_name(&self) -> OsString {
@@ -412,7 +413,7 @@ pub fn rename<P, Q>(arch: &Archive, from: P, to: Q) -> Result<(), i32>
}
}
-fn readdir(arch: &Archive, p: &Path) -> Result<ReadDir, i32> {
+fn readdir<'a>(arch: &'a Archive, p: &Path) -> Result<ReadDir<'a>, 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<ReadDir, i32> {
if r < 0 {
Err(r)
} else {
- Ok(ReadDir { handle: Dir(handle), root: root })
+ Ok(ReadDir { handle: Dir(handle), root: root, arch: arch})
}
}
}