Fix dir entries pointing to root directory.
Fixes 'ls dir/..'.
This commit is contained in:
parent
f850c76a1b
commit
a974a61cb8
17
src/dir.rs
17
src/dir.rs
@ -191,18 +191,19 @@ impl <'a, 'b> DirEntry<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_file(&self) -> File<'a, 'b> {
|
pub fn to_file(&self) -> File<'a, 'b> {
|
||||||
if self.is_dir() {
|
assert!(!self.is_dir(), "Not a file entry");
|
||||||
panic!("This is a directory");
|
|
||||||
}
|
|
||||||
File::new(self.first_cluster(), Some(self.data.size), self.fs)
|
File::new(self.first_cluster(), Some(self.data.size), self.fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_dir(&self) -> Dir<'a, 'b> {
|
pub fn to_dir(&self) -> Dir<'a, 'b> {
|
||||||
if !self.is_dir() {
|
assert!(self.is_dir(), "Not a directory entry");
|
||||||
panic!("This is a file");
|
match self.first_cluster() {
|
||||||
|
Some(n) => {
|
||||||
|
let file = File::new(Some(n), None, self.fs);
|
||||||
|
Dir::new(DirRawStream::File(file), self.fs)
|
||||||
|
},
|
||||||
|
None => self.fs.root_dir(),
|
||||||
}
|
}
|
||||||
let file = File::new(self.first_cluster(), None, self.fs);
|
|
||||||
Dir::new(DirRawStream::File(file), self.fs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> u64 {
|
pub fn len(&self) -> u64 {
|
||||||
@ -250,7 +251,7 @@ impl <'a, 'b> Dir<'a, 'b> {
|
|||||||
|
|
||||||
fn split_path<'c>(path: &'c str) -> (&'c str, Option<&'c str>) {
|
fn split_path<'c>(path: &'c str) -> (&'c str, Option<&'c str>) {
|
||||||
let mut path_split = path.trim_matches('/').splitn(2, "/");
|
let mut path_split = path.trim_matches('/').splitn(2, "/");
|
||||||
let comp = path_split.next().unwrap();
|
let comp = path_split.next().unwrap(); // safe unwrap - splitn always returns at least one element
|
||||||
let rest_opt = path_split.next();
|
let rest_opt = path_split.next();
|
||||||
(comp, rest_opt)
|
(comp, rest_opt)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user