Skip to content

Commit e069969

Browse files
committed
changed naming of variables and added a comment
1 parent 4cef7f2 commit e069969

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

library/std/src/fs.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,16 +3334,19 @@ impl DirBuilder {
33343334
}
33353335

33363336
let ancestors = path.ancestors();
3337-
let mut uncreated_dir_ctr = 0;
3337+
let mut uncreated_dirs = 0;
33383338

33393339
for ancestor in ancestors {
3340+
// for relative paths like "foo/bar", the parent of
3341+
// "foo" will be "" which there's no need to invoke
3342+
// a mkdir syscall on
33403343
if ancestor == Path::new("") {
33413344
break;
33423345
}
33433346

33443347
match self.inner.mkdir(ancestor) {
33453348
Ok(()) => break,
3346-
Err(e) if e.kind() == io::ErrorKind::NotFound => uncreated_dir_ctr += 1,
3349+
Err(e) if e.kind() == io::ErrorKind::NotFound => uncreated_dirs += 1,
33473350
// we check if the err is AlreadyExists for two reasons
33483351
// - in case the path exists as a *file*
33493352
// - and to avoid calls to .is_dir() in case of other errs
@@ -3354,10 +3357,10 @@ impl DirBuilder {
33543357
}
33553358

33563359
// collect only the uncreated directories w/o letting the vec resize
3357-
let mut uncreated_dirs = Vec::with_capacity(uncreated_dir_ctr);
3358-
uncreated_dirs.extend(ancestors.take(uncreated_dir_ctr));
3360+
let mut uncreated_dirs_vec = Vec::with_capacity(uncreated_dirs);
3361+
uncreated_dirs_vec.extend(ancestors.take(uncreated_dirs));
33593362

3360-
for uncreated_dir in uncreated_dirs.iter().rev() {
3363+
for uncreated_dir in uncreated_dirs_vec.iter().rev() {
33613364
if let Err(e) = self.inner.mkdir(uncreated_dir) {
33623365
if e.kind() != io::ErrorKind::AlreadyExists || !uncreated_dir.is_dir() {
33633366
return Err(e);

0 commit comments

Comments
 (0)