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