@@ -9,6 +9,7 @@ use lightning::util::ser::{Writeable, Readable};
9
9
use bitcoin:: hash_types:: { BlockHash , Txid } ;
10
10
use bitcoin:: hashes:: hex:: { ToHex , FromHex } ;
11
11
use std:: fs;
12
+ use std:: path:: Path ;
12
13
use std:: io:: { Error , ErrorKind , Cursor } ;
13
14
use std:: collections:: HashMap ;
14
15
use std:: marker:: PhantomData ;
@@ -31,7 +32,10 @@ impl<ChanSigner: ChannelKeys + Readable + Writeable> FilesystemPersister<ChanSig
31
32
}
32
33
33
34
fn get_full_filepath ( & self , funding_txo : OutPoint ) -> String {
34
- format ! ( "{}/{}_{}" , self . path_to_channel_data, funding_txo. txid. to_hex( ) , funding_txo. index)
35
+ let path = Path :: new ( & self . path_to_channel_data ) ;
36
+ let mut path_buf = path. to_path_buf ( ) ;
37
+ path_buf. push ( format ! ( "{}_{}" , funding_txo. txid. to_hex( ) , funding_txo. index) ) ;
38
+ path_buf. to_str ( ) . unwrap ( ) . to_string ( )
35
39
}
36
40
37
41
fn write_channel_data ( & self , funding_txo : OutPoint , monitor : & ChannelMonitor < ChanSigner > ) -> std:: io:: Result < ( ) > {
@@ -65,13 +69,13 @@ impl<ChanSigner: ChannelKeys + Readable + Writeable> FilesystemPersister<ChanSig
65
69
if need_bk {
66
70
fs:: copy ( & filename, & bk_filename) ?;
67
71
{
68
- let f = fs:: File :: open ( & bk_filename) ?;
72
+ let f = fs:: OpenOptions :: new ( ) . write ( true ) . open ( & bk_filename) ?;
69
73
f. sync_all ( ) ?;
70
74
}
71
75
}
72
76
fs:: rename ( & tmp_filename, & filename) ?;
73
77
{
74
- let f = fs:: File :: open ( & filename) ?;
78
+ let f = fs:: OpenOptions :: new ( ) . write ( true ) . open ( & filename) ?;
75
79
f. sync_all ( ) ?;
76
80
}
77
81
if need_bk {
@@ -148,8 +152,8 @@ mod tests {
148
152
#[ test]
149
153
fn test_filesystem_data_persister ( ) {
150
154
// Create the nodes, giving them FilesystemPersisters for data persisters.
151
- let data_persister_0: FilesystemPersister < EnforcingChannelKeys > = FilesystemPersister :: new ( "./ persister0" . to_string ( ) ) ;
152
- let data_persister_1: FilesystemPersister < EnforcingChannelKeys > = FilesystemPersister :: new ( "./ persister1" . to_string ( ) ) ;
155
+ let data_persister_0: FilesystemPersister < EnforcingChannelKeys > = FilesystemPersister :: new ( "persister0" . to_string ( ) ) ;
156
+ let data_persister_1: FilesystemPersister < EnforcingChannelKeys > = FilesystemPersister :: new ( "persister1" . to_string ( ) ) ;
153
157
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
154
158
let mut node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
155
159
let chain_mon_0 = test_utils:: TestChainMonitor :: new ( Some ( & chanmon_cfgs[ 0 ] . chain_source ) , & chanmon_cfgs[ 0 ] . tx_broadcaster , & chanmon_cfgs[ 0 ] . logger , & chanmon_cfgs[ 0 ] . fee_estimator , & data_persister_0) ;
0 commit comments