Skip to content

Commit c51b9f0

Browse files
authored
make sure we dont delete beyond root of the storage (#289)
1 parent da70cbc commit c51b9f0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

examples/index_configs/wikipedia_index_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{
1414
"name": "url",
1515
"type": "text",
16-
"indexed": "false",
16+
"indexed": false,
1717
"stored": false
1818
}
1919
]

quickwit-storage/src/local_file_storage.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,17 @@ fn delete_all_dirs(root: PathBuf, path: &Path) -> BoxFuture<'_, std::io::Result<
100100
}
101101
let _ = delete_result?;
102102
}
103-
if let Some(parent) = path.parent() {
104-
delete_all_dirs(root, parent).await?;
103+
104+
match &path.parent() {
105+
Some(path) => {
106+
if path == &Path::new("") || path == &Path::new(".") {
107+
return Ok(());
108+
}
109+
delete_all_dirs(root, path).await?;
110+
}
111+
_ => return Ok(()),
105112
}
113+
106114
Ok(())
107115
}
108116
.boxed()
@@ -286,9 +294,15 @@ mod tests {
286294
tokio::fs::File::create(intermediate_file.clone()).await?;
287295
assert_eq!(dir_path.exists(), true);
288296
assert_eq!(intermediate_file.exists(), true);
289-
delete_all_dirs(path_root, dir_path.as_path()).await?;
297+
delete_all_dirs(path_root.clone(), dir_path.as_path()).await?;
290298
assert_eq!(dir_path.exists(), false);
291299
assert_eq!(dir_path.parent().unwrap().exists(), true);
300+
301+
// make sure it does not go beyond the path
302+
tokio::fs::create_dir_all(path_root.join("home/foo/bar")).await?;
303+
delete_all_dirs(path_root.join("home/foo"), Path::new("bar")).await?;
304+
assert_eq!(path_root.join("home/foo").exists(), true);
305+
292306
Ok(())
293307
}
294308
}

0 commit comments

Comments
 (0)