Catch only NotFound error in create_file and create_dir.

This commit is contained in:
Rafał Harabień 2017-11-07 01:06:52 +01:00
parent 21bd2a0e8d
commit 4613196733

View File

@ -542,8 +542,10 @@ impl <'a, 'b> Dir<'a, 'b> {
Some(rest) => r?.to_dir().create_file(rest), Some(rest) => r?.to_dir().create_file(rest),
None => { None => {
match r { match r {
Err(_) => Ok(self.create_entry(name, FileAttributes::from_bits_truncate(0), None)?.to_file()), Err(ref err) if err.kind() == ErrorKind::NotFound =>
Ok(e) => Ok(e.to_file()) Ok(self.create_entry(name, FileAttributes::from_bits_truncate(0), None)?.to_file()),
Err(err) => Err(err),
Ok(e) => Ok(e.to_file()),
} }
} }
} }
@ -557,7 +559,7 @@ impl <'a, 'b> Dir<'a, 'b> {
Some(rest) => r?.to_dir().create_dir(rest), Some(rest) => r?.to_dir().create_dir(rest),
None => { None => {
match r { match r {
Err(_) => { Err(ref err) if err.kind() == ErrorKind::NotFound => {
let cluster = self.fs.alloc_cluster(None)?; let cluster = self.fs.alloc_cluster(None)?;
let entry = self.create_entry(name, FileAttributes::DIRECTORY, Some(cluster))?; let entry = self.create_entry(name, FileAttributes::DIRECTORY, Some(cluster))?;
let mut dir = entry.to_dir(); let mut dir = entry.to_dir();
@ -565,6 +567,7 @@ impl <'a, 'b> Dir<'a, 'b> {
dir.create_entry("..", FileAttributes::DIRECTORY, self.stream.first_cluster())?; dir.create_entry("..", FileAttributes::DIRECTORY, self.stream.first_cluster())?;
Ok(dir) Ok(dir)
}, },
Err(err) => Err(err),
Ok(e) => Ok(e.to_dir()), Ok(e) => Ok(e.to_dir()),
} }
} }