@@ -73,42 +73,41 @@ impl FilesystemPersister {
73
73
for file_option in fs:: read_dir ( path) . unwrap ( ) {
74
74
let file = file_option. unwrap ( ) ;
75
75
let owned_file_name = file. file_name ( ) ;
76
- let filename = owned_file_name. to_str ( ) ;
77
- if !filename. is_some ( ) || !filename. unwrap ( ) . is_ascii ( ) || filename. unwrap ( ) . len ( ) < 65 {
76
+ let filename = owned_file_name. to_str ( )
77
+ . ok_or_else ( || std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidData ,
78
+ "File name is not a valid utf8 string" ) ) ?;
79
+ if !filename. is_ascii ( ) || filename. len ( ) < 65 {
78
80
return Err ( std:: io:: Error :: new (
79
81
std:: io:: ErrorKind :: InvalidData ,
80
82
"Invalid ChannelMonitor file name" ,
81
83
) ) ;
82
84
}
83
- if filename. unwrap ( ) . ends_with ( ".tmp" ) {
85
+ if filename. ends_with ( ".tmp" ) {
84
86
// If we were in the middle of committing an new update and crashed, it should be
85
87
// safe to ignore the update - we should never have returned to the caller and
86
88
// irrevocably committed to the new state in any way.
87
89
continue ;
88
90
}
89
91
90
- let txid = Txid :: from_hex ( filename. unwrap ( ) . split_at ( 64 ) . 0 ) ;
91
- if txid. is_err ( ) {
92
- return Err ( std:: io:: Error :: new (
92
+ let txid = Txid :: from_hex ( filename. split_at ( 64 ) . 0 )
93
+ . map_err ( |_| std:: io:: Error :: new (
93
94
std:: io:: ErrorKind :: InvalidData ,
94
95
"Invalid tx ID in filename" ,
95
- ) ) ;
96
- }
96
+ ) ) ?;
97
97
98
- let index = filename. unwrap ( ) . split_at ( 65 ) . 1 . parse ( ) ;
99
- if index. is_err ( ) {
100
- return Err ( std:: io:: Error :: new (
98
+ let index = filename. split_at ( 65 ) . 1 . parse ( )
99
+ . map_err ( |_| std:: io:: Error :: new (
101
100
std:: io:: ErrorKind :: InvalidData ,
102
101
"Invalid tx index in filename" ,
103
- ) ) ;
104
- }
102
+ ) ) ?;
105
103
106
104
let contents = fs:: read ( & file. path ( ) ) ?;
107
105
let mut buffer = Cursor :: new ( & contents) ;
108
106
match <( BlockHash , ChannelMonitor < <K :: Target as SignerProvider >:: Signer > ) >:: read ( & mut buffer, & * keys_manager) {
109
107
Ok ( ( blockhash, channel_monitor) ) => {
110
- if channel_monitor. get_funding_txo ( ) . 0 . txid != txid. unwrap ( ) || channel_monitor. get_funding_txo ( ) . 0 . index != index. unwrap ( ) {
111
- return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidData , "ChannelMonitor was stored in the wrong file" ) ) ;
108
+ if channel_monitor. get_funding_txo ( ) . 0 . txid != txid || channel_monitor. get_funding_txo ( ) . 0 . index != index {
109
+ return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidData ,
110
+ "ChannelMonitor was stored in the wrong file" ) ) ;
112
111
}
113
112
res. push ( ( blockhash, channel_monitor) ) ;
114
113
}
0 commit comments