Skip to content

Commit 68b2fa5

Browse files
committed
f Error if file can't be found or is not a file
1 parent 58ab00b commit 68b2fa5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,28 @@ impl KVStore for FilesystemStore {
259259
let entry = entry?;
260260
let p = entry.path();
261261

262-
if !p.is_file() {
263-
continue;
264-
}
265-
266262
if let Some(ext) = p.extension() {
267263
if ext == "tmp" {
268264
continue;
269265
}
270266
}
271267

268+
let metadata = p.metadata()?;
269+
270+
// We allow the presence of directories in the empty namespace and just skip them.
271+
if metadata.is_dir() && namespace == "" {
272+
continue;
273+
}
274+
275+
// If we otherwise don't find a file at the given path something went wrong.
276+
if !metadata.is_file() {
277+
debug_assert!(false, "Failed to list keys of namespace {}: file is not present.",
278+
PrintableString(namespace));
279+
let msg = format!("Failed to list keys of namespace {}: file is not present.",
280+
PrintableString(namespace));
281+
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
282+
}
283+
272284
if let Some(relative_path) = p.strip_prefix(&prefixed_dest).ok()
273285
.and_then(|p| p.to_str()) {
274286
if relative_path.chars().all(|c| c.is_ascii() && !c.is_control()) {

0 commit comments

Comments
 (0)