forked from M-Labs/rust-fatfs
Avoid building short name when traversing path
This commit is contained in:
parent
282c40fad2
commit
0b22cfa0b3
16
src/dir.rs
16
src/dir.rs
@ -138,11 +138,13 @@ impl <'a, 'b> Dir<'a, 'b> {
|
|||||||
/// Creates new file or opens existing without truncating.
|
/// Creates new file or opens existing without truncating.
|
||||||
pub fn create_file(&mut self, path: &str) -> io::Result<File<'a, 'b>> {
|
pub fn create_file(&mut self, path: &str) -> io::Result<File<'a, 'b>> {
|
||||||
let (name, rest_opt) = split_path(path);
|
let (name, rest_opt) = split_path(path);
|
||||||
|
match rest_opt {
|
||||||
|
// path contains more than 1 component
|
||||||
|
Some(rest) => self.find_entry(name, None)?.to_dir().create_file(rest),
|
||||||
|
None => {
|
||||||
|
// this is final filename in the path
|
||||||
let mut short_name_gen = ShortNameGenerator::new(name);
|
let mut short_name_gen = ShortNameGenerator::new(name);
|
||||||
let r = self.find_entry(name, Some(&mut short_name_gen));
|
let r = self.find_entry(name, Some(&mut short_name_gen));
|
||||||
match rest_opt {
|
|
||||||
Some(rest) => r?.to_dir().create_file(rest),
|
|
||||||
None => {
|
|
||||||
match r {
|
match r {
|
||||||
Err(ref err) if err.kind() == ErrorKind::NotFound => {
|
Err(ref err) if err.kind() == ErrorKind::NotFound => {
|
||||||
let short_name = short_name_gen.generate()?;
|
let short_name = short_name_gen.generate()?;
|
||||||
@ -158,11 +160,13 @@ impl <'a, 'b> Dir<'a, 'b> {
|
|||||||
/// Creates new directory or opens existing.
|
/// Creates new directory or opens existing.
|
||||||
pub fn create_dir(&mut self, path: &str) -> io::Result<Dir<'a, 'b>> {
|
pub fn create_dir(&mut self, path: &str) -> io::Result<Dir<'a, 'b>> {
|
||||||
let (name, rest_opt) = split_path(path);
|
let (name, rest_opt) = split_path(path);
|
||||||
|
match rest_opt {
|
||||||
|
// path contains more than 1 component
|
||||||
|
Some(rest) => self.find_entry(name, None)?.to_dir().create_dir(rest),
|
||||||
|
None => {
|
||||||
|
// this is final filename in the path
|
||||||
let mut short_name_gen = ShortNameGenerator::new(name);
|
let mut short_name_gen = ShortNameGenerator::new(name);
|
||||||
let r = self.find_entry(name, Some(&mut short_name_gen));
|
let r = self.find_entry(name, Some(&mut short_name_gen));
|
||||||
match rest_opt {
|
|
||||||
Some(rest) => r?.to_dir().create_dir(rest),
|
|
||||||
None => {
|
|
||||||
match r {
|
match r {
|
||||||
Err(ref err) if err.kind() == ErrorKind::NotFound => {
|
Err(ref err) if err.kind() == ErrorKind::NotFound => {
|
||||||
// alloc cluster for directory data
|
// alloc cluster for directory data
|
||||||
|
Loading…
Reference in New Issue
Block a user