Skip to content

Commit bc73b39

Browse files
committed
f Account for KVStore::read returning a Vec<u8>
1 parent 474b01b commit bc73b39

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ impl FilesystemStore {
5050
}
5151

5252
impl KVStore for FilesystemStore {
53-
type Reader = FilesystemReader;
54-
55-
fn read(&self, namespace: &str, key: &str) -> std::io::Result<Self::Reader> {
53+
fn read(&self, namespace: &str, key: &str) -> std::io::Result<Vec<u8>> {
5654
if key.is_empty() {
5755
let msg = format!("Failed to read {}/{}: key may not be empty.",
5856
PrintableString(namespace), PrintableString(key));
@@ -74,8 +72,15 @@ impl KVStore for FilesystemStore {
7472

7573
let mut outer_lock = self.locks.lock().unwrap();
7674
let inner_lock_ref = Arc::clone(&outer_lock.entry(dest_file_path.clone()).or_default());
75+
let _guard = inner_lock_ref.read().unwrap();
76+
77+
let mut buf = Vec::new();
78+
let f = fs::File::open(dest_file_path.clone())?;
79+
let mut reader = BufReader::new(f);
80+
let nread = reader.read_to_end(&mut buf)?;
81+
debug_assert_ne!(nread, 0);
7782

78-
FilesystemReader::new(dest_file_path, inner_lock_ref)
83+
Ok(buf)
7984
}
8085

8186
fn write(&self, namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
@@ -266,27 +271,6 @@ impl KVStore for FilesystemStore {
266271
}
267272
}
268273

269-
/// A buffered [`Read`] implementation as returned from [`FilesystemStore::read`].
270-
pub struct FilesystemReader {
271-
inner: BufReader<fs::File>,
272-
lock_ref: Arc<RwLock<()>>,
273-
}
274-
275-
impl FilesystemReader {
276-
fn new(dest_file_path: PathBuf, lock_ref: Arc<RwLock<()>>) -> std::io::Result<Self> {
277-
let f = fs::File::open(dest_file_path.clone())?;
278-
let inner = BufReader::new(f);
279-
Ok(Self { inner, lock_ref })
280-
}
281-
}
282-
283-
impl Read for FilesystemReader {
284-
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
285-
let _guard = self.lock_ref.read().unwrap();
286-
self.inner.read(buf)
287-
}
288-
}
289-
290274
#[cfg(test)]
291275
mod tests {
292276
use super::*;

0 commit comments

Comments
 (0)