@@ -28,8 +28,8 @@ use std::io::Cursor;
28
28
use std:: ops:: Deref ;
29
29
use std:: path:: { Path , PathBuf } ;
30
30
31
- /// FilesystemPersister persists channel data on disk, where each channel's
32
- /// data is stored in a file named after its funding outpoint.
31
+ /// ` FilesystemPersister` persists a given `Writeable` object on disk. In the case of channel data,
32
+ /// it is stored in a file named after its funding outpoint.
33
33
///
34
34
/// Warning: this module does the best it can with calls to persist data, but it
35
35
/// can only guarantee that the data is passed to the drive. It is up to the
@@ -39,23 +39,22 @@ use std::path::{Path, PathBuf};
39
39
/// persistent.
40
40
/// Corollary: especially when dealing with larger amounts of money, it is best
41
41
/// practice to have multiple channel data backups and not rely only on one
42
- /// FilesystemPersister.
42
+ /// ` FilesystemPersister` .
43
43
pub struct FilesystemPersister {
44
- path_to_channel_data : String ,
44
+ path_to_data : String ,
45
45
}
46
46
47
47
impl FilesystemPersister {
48
- /// Initialize a new FilesystemPersister and set the path to the individual channels'
49
- /// files.
50
- pub fn new ( path_to_channel_data : String ) -> Self {
48
+ /// Initialize a new FilesystemPersister and set the parent path of the individual files.
49
+ pub fn new ( path_to_data : String ) -> Self {
51
50
return Self {
52
- path_to_channel_data ,
51
+ path_to_data ,
53
52
}
54
53
}
55
54
56
55
/// Get the directory which was provided when this persister was initialized.
57
56
pub fn get_data_dir ( & self ) -> String {
58
- self . path_to_channel_data . clone ( )
57
+ self . path_to_data . clone ( )
59
58
}
60
59
61
60
/// Read `ChannelMonitor`s from disk.
@@ -64,7 +63,7 @@ impl FilesystemPersister {
64
63
) -> Result < Vec < ( BlockHash , ChannelMonitor < Signer > ) > , std:: io:: Error >
65
64
where K :: Target : KeysInterface < Signer =Signer > + Sized ,
66
65
{
67
- let mut path = PathBuf :: from ( & self . path_to_channel_data ) ;
66
+ let mut path = PathBuf :: from ( & self . path_to_data ) ;
68
67
path. push ( "monitors" ) ;
69
68
if !Path :: new ( & path) . exists ( ) {
70
69
return Ok ( Vec :: new ( ) ) ;
@@ -124,13 +123,13 @@ impl FilesystemPersister {
124
123
125
124
impl KVStorePersister for FilesystemPersister {
126
125
fn persist < W : Writeable > ( & self , key : & str , object : & W ) -> std:: io:: Result < ( ) > {
127
- let mut dest_file = PathBuf :: from ( self . path_to_channel_data . clone ( ) ) ;
126
+ let mut dest_file = PathBuf :: from ( self . path_to_data . clone ( ) ) ;
128
127
dest_file. push ( key) ;
129
128
util:: write_to_file ( dest_file, object)
130
129
}
131
130
132
131
fn unpersist ( & self , key : & str ) -> std:: io:: Result < bool > {
133
- let mut dest_file = PathBuf :: from ( self . path_to_channel_data . clone ( ) ) ;
132
+ let mut dest_file = PathBuf :: from ( self . path_to_data . clone ( ) ) ;
134
133
dest_file. push ( key) ;
135
134
util:: delete_file ( dest_file)
136
135
}
@@ -164,7 +163,7 @@ mod tests {
164
163
fn drop ( & mut self ) {
165
164
// We test for invalid directory names, so it's OK if directory removal
166
165
// fails.
167
- match fs:: remove_dir_all ( & self . path_to_channel_data ) {
166
+ match fs:: remove_dir_all ( & self . path_to_data ) {
168
167
Err ( e) => println ! ( "Failed to remove test persister directory: {}" , e) ,
169
168
_ => { }
170
169
}
@@ -248,7 +247,7 @@ mod tests {
248
247
#[ test]
249
248
fn test_readonly_dir_perm_failure ( ) {
250
249
let persister = FilesystemPersister :: new ( "test_readonly_dir_perm_failure" . to_string ( ) ) ;
251
- fs:: create_dir_all ( & persister. path_to_channel_data ) . unwrap ( ) ;
250
+ fs:: create_dir_all ( & persister. path_to_data ) . unwrap ( ) ;
252
251
253
252
// Set up a dummy channel and force close. This will produce a monitor
254
253
// that we can then use to test persistence.
@@ -266,7 +265,7 @@ mod tests {
266
265
// Set the persister's directory to read-only, which should result in
267
266
// returning a permanent failure when we then attempt to persist a
268
267
// channel update.
269
- let path = & persister. path_to_channel_data ;
268
+ let path = & persister. path_to_data ;
270
269
let mut perms = fs:: metadata ( path) . unwrap ( ) . permissions ( ) ;
271
270
perms. set_readonly ( true ) ;
272
271
fs:: set_permissions ( path, perms) . unwrap ( ) ;
0 commit comments