@@ -75,10 +75,13 @@ impl KVStore for FilesystemStore {
75
75
dest_file_path. push ( namespace) ;
76
76
dest_file_path. push ( key) ;
77
77
78
- let msg = format ! ( "Could not retrieve parent directory of {}." , dest_file_path. display( ) ) ;
79
78
let parent_directory = dest_file_path
80
79
. parent ( )
81
- . ok_or ( std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , msg) ) ?
80
+ . ok_or_else ( || {
81
+ let msg =
82
+ format ! ( "Could not retrieve parent directory of {}." , dest_file_path. display( ) ) ;
83
+ std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , msg)
84
+ } ) ?
82
85
. to_path_buf ( ) ;
83
86
fs:: create_dir_all ( parent_directory. clone ( ) ) ?;
84
87
@@ -151,11 +154,11 @@ impl KVStore for FilesystemStore {
151
154
fs:: remove_file ( & dest_file_path) ?;
152
155
#[ cfg( not( target_os = "windows" ) ) ]
153
156
{
154
- let msg =
155
- format ! ( "Could not retrieve parent directory of {}." , dest_file_path . display ( ) ) ;
156
- let parent_directory = dest_file_path
157
- . parent ( )
158
- . ok_or ( std :: io :: Error :: new ( std :: io :: ErrorKind :: InvalidInput , msg ) ) ?;
157
+ let parent_directory = dest_file_path . parent ( ) . ok_or_else ( || {
158
+ let msg =
159
+ format ! ( "Could not retrieve parent directory of {}." , dest_file_path. display ( ) ) ;
160
+ std :: io :: Error :: new ( std :: io :: ErrorKind :: InvalidInput , msg )
161
+ } ) ?;
159
162
let dir_file = fs:: OpenOptions :: new ( ) . read ( true ) . open ( parent_directory) ?;
160
163
unsafe {
161
164
// The above call to `fs::remove_file` corresponds to POSIX `unlink`, whose changes
@@ -245,20 +248,21 @@ impl Read for FilesystemReader {
245
248
246
249
impl KVStorePersister for FilesystemStore {
247
250
fn persist < W : Writeable > ( & self , prefixed_key : & str , object : & W ) -> lightning:: io:: Result < ( ) > {
248
- let msg = format ! ( "Could not persist file for key {}." , prefixed_key) ;
249
251
let dest_file_path = PathBuf :: from_str ( prefixed_key) . map_err ( |_| {
250
- lightning:: io:: Error :: new ( lightning:: io:: ErrorKind :: InvalidInput , msg. clone ( ) )
252
+ let msg = format ! ( "Could not persist file for key {}." , prefixed_key) ;
253
+ lightning:: io:: Error :: new ( lightning:: io:: ErrorKind :: InvalidInput , msg)
251
254
} ) ?;
252
255
253
- let parent_directory = dest_file_path. parent ( ) . ok_or ( lightning :: io :: Error :: new (
254
- lightning :: io :: ErrorKind :: InvalidInput ,
255
- msg . clone ( ) ,
256
- ) ) ?;
256
+ let parent_directory = dest_file_path. parent ( ) . ok_or_else ( || {
257
+ let msg = format ! ( "Could not persist file for key {}." , prefixed_key ) ;
258
+ lightning :: io :: Error :: new ( lightning :: io :: ErrorKind :: InvalidInput , msg )
259
+ } ) ?;
257
260
let namespace = parent_directory. display ( ) . to_string ( ) ;
258
261
259
- let dest_without_namespace = dest_file_path
260
- . strip_prefix ( & namespace)
261
- . map_err ( |_| lightning:: io:: Error :: new ( lightning:: io:: ErrorKind :: InvalidInput , msg) ) ?;
262
+ let dest_without_namespace = dest_file_path. strip_prefix ( & namespace) . map_err ( |_| {
263
+ let msg = format ! ( "Could not persist file for key {}." , prefixed_key) ;
264
+ lightning:: io:: Error :: new ( lightning:: io:: ErrorKind :: InvalidInput , msg)
265
+ } ) ?;
262
266
let key = dest_without_namespace. display ( ) . to_string ( ) ;
263
267
264
268
self . write ( & namespace, & key, & object. encode ( ) ) ?;
0 commit comments