@@ -9,6 +9,7 @@ use lightning::util::ser::{Writeable, Readable};
99use bitcoin:: hash_types:: { BlockHash , Txid } ;
1010use bitcoin:: hashes:: hex:: { ToHex , FromHex } ;
1111use std:: fs;
12+ use std:: path:: Path ;
1213use std:: io:: { Error , ErrorKind , Cursor } ;
1314use std:: collections:: HashMap ;
1415use std:: marker:: PhantomData ;
@@ -31,7 +32,10 @@ impl<ChanSigner: ChannelKeys + Readable + Writeable> FilesystemPersister<ChanSig
3132 }
3233
3334 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 ( )
3539 }
3640
3741 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
6569 if need_bk {
6670 fs:: copy ( & filename, & bk_filename) ?;
6771 {
68- let f = fs:: File :: open ( & bk_filename) ?;
72+ let f = fs:: OpenOptions :: new ( ) . write ( true ) . open ( & bk_filename) ?;
6973 f. sync_all ( ) ?;
7074 }
7175 }
7276 fs:: rename ( & tmp_filename, & filename) ?;
7377 {
74- let f = fs:: File :: open ( & filename) ?;
78+ let f = fs:: OpenOptions :: new ( ) . write ( true ) . open ( & filename) ?;
7579 f. sync_all ( ) ?;
7680 }
7781 if need_bk {
@@ -148,8 +152,8 @@ mod tests {
148152 #[ test]
149153 fn test_filesystem_data_persister ( ) {
150154 // 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 ( ) ) ;
153157 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
154158 let mut node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
155159 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