@@ -50,9 +50,7 @@ impl FilesystemStore {
50
50
}
51
51
52
52
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 > > {
56
54
if key. is_empty ( ) {
57
55
let msg = format ! ( "Failed to read {}/{}: key may not be empty." ,
58
56
PrintableString ( namespace) , PrintableString ( key) ) ;
@@ -74,8 +72,15 @@ impl KVStore for FilesystemStore {
74
72
75
73
let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
76
74
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 ) ;
77
82
78
- FilesystemReader :: new ( dest_file_path , inner_lock_ref )
83
+ Ok ( buf )
79
84
}
80
85
81
86
fn write ( & self , namespace : & str , key : & str , buf : & [ u8 ] ) -> std:: io:: Result < ( ) > {
@@ -266,27 +271,6 @@ impl KVStore for FilesystemStore {
266
271
}
267
272
}
268
273
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
-
290
274
#[ cfg( test) ]
291
275
mod tests {
292
276
use super :: * ;
0 commit comments