Skip to content

Commit c9dd876

Browse files
avoid erroring for top-level directory entries
1 parent 7332eb6 commit c9dd876

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/read/pipelining.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ pub mod path_splitting {
6161
}
6262
}
6363
}
64-
if ret.is_empty() {
65-
return Err(PathSplitError::ExtractionPathEscapesDirectory(
66-
entry_path,
67-
"path resolves to the top-level directory",
68-
));
69-
}
7064

7165
Ok((ret, is_dir))
7266
}
@@ -131,6 +125,13 @@ pub mod path_splitting {
131125
/* Split entries by directory components, and normalize any non-literal paths
132126
* (e.g. '..', '.', leading '/', repeated '/'). */
133127
let (all_components, is_dir) = normalize_parent_dirs(entry_path)?;
128+
129+
/* If the entry resolves to the top-level directory, we don't error, but instead just
130+
* avoid writing any data to that directory entry. */
131+
if all_components.is_empty() {
132+
continue;
133+
}
134+
134135
/* If the entry is a directory by mode, then it does not need to end in '/'. */
135136
let is_dir = is_dir || data.is_dir_by_mode();
136137
/* Split basename and dirname. */
@@ -209,7 +210,7 @@ pub mod path_splitting {
209210
(vec!["a\\b"], true)
210211
);
211212
assert!(normalize_parent_dirs("a/../../b").is_err());
212-
assert!(normalize_parent_dirs("./").is_err());
213+
assert_eq!(normalize_parent_dirs("./").unwrap(), (vec![], true));
213214
}
214215

215216
#[test]

0 commit comments

Comments
 (0)