Skip to content

Commit e22601e

Browse files
committed
f More winblowz fixing
1 parent 6d83145 commit e22601e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lightning-storage/src/fs_store.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ impl KVStore for FilesystemStore {
6262
let lock_key = (namespace.to_string(), key.to_string());
6363
let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key).or_default());
6464

65+
if key.is_empty() {
66+
let msg = format!("Failed to read {}/{}: key may not be empty.", namespace, key);
67+
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
68+
}
69+
6570
let mut dest_file_path = self.data_dir.clone();
6671
dest_file_path.push(namespace);
6772
dest_file_path.push(key);
@@ -74,6 +79,11 @@ impl KVStore for FilesystemStore {
7479
let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key).or_default());
7580
let _guard = inner_lock_ref.write().unwrap();
7681

82+
if key.is_empty() {
83+
let msg = format!("Failed to write {}/{}: key may not be empty.", namespace, key);
84+
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
85+
}
86+
7787
let mut dest_file_path = self.data_dir.clone();
7888
dest_file_path.push(namespace);
7989
dest_file_path.push(key);
@@ -148,6 +158,11 @@ impl KVStore for FilesystemStore {
148158

149159
let _guard = inner_lock_ref.write().unwrap();
150160

161+
if key.is_empty() {
162+
let msg = format!("Failed to remove {}/{}: key may not be empty.", namespace, key);
163+
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
164+
}
165+
151166
let mut dest_file_path = self.data_dir.clone();
152167
dest_file_path.push(namespace);
153168
dest_file_path.push(key);

lightning-storage/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub(crate) fn do_read_write_remove_list_persist<K: KVStore>(kv_store: &K) {
1717

1818
// Test empty namespace is allowed, but not empty key.
1919
kv_store.write("", key, &data).unwrap();
20+
println!("ERR: {:?}", kv_store.write(namespace, "", &data));
2021
assert!(kv_store.write(namespace, "", &data).is_err());
2122

2223
let listed_keys = kv_store.list(namespace).unwrap();

0 commit comments

Comments
 (0)