Skip to content

Commit f0373ee

Browse files
committed
Reword FP docs to reflect more general usage
Since `FilesystemPersister` is used for different types of `Writeables`, not only channel data, we can now reword the docs to reflect its more general use case.
1 parent c21b310 commit f0373ee

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lightning-persister/src/lib.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use std::io::Cursor;
2828
use std::ops::Deref;
2929
use std::path::{Path, PathBuf};
3030

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.
3333
///
3434
/// Warning: this module does the best it can with calls to persist data, but it
3535
/// 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};
3939
/// persistent.
4040
/// Corollary: especially when dealing with larger amounts of money, it is best
4141
/// practice to have multiple channel data backups and not rely only on one
42-
/// FilesystemPersister.
42+
/// `FilesystemPersister`.
4343
pub struct FilesystemPersister {
44-
path_to_channel_data: String,
44+
path_to_data: String,
4545
}
4646

4747
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 {
5150
return Self {
52-
path_to_channel_data,
51+
path_to_data,
5352
}
5453
}
5554

5655
/// Get the directory which was provided when this persister was initialized.
5756
pub fn get_data_dir(&self) -> String {
58-
self.path_to_channel_data.clone()
57+
self.path_to_data.clone()
5958
}
6059

6160
/// Read `ChannelMonitor`s from disk.
@@ -64,7 +63,7 @@ impl FilesystemPersister {
6463
) -> Result<Vec<(BlockHash, ChannelMonitor<Signer>)>, std::io::Error>
6564
where K::Target: KeysInterface<Signer=Signer> + Sized,
6665
{
67-
let mut path = PathBuf::from(&self.path_to_channel_data);
66+
let mut path = PathBuf::from(&self.path_to_data);
6867
path.push("monitors");
6968
if !Path::new(&path).exists() {
7069
return Ok(Vec::new());
@@ -124,13 +123,13 @@ impl FilesystemPersister {
124123

125124
impl KVStorePersister for FilesystemPersister {
126125
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());
128127
dest_file.push(key);
129128
util::write_to_file(dest_file, object)
130129
}
131130

132131
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());
134133
dest_file.push(key);
135134
util::delete_file(dest_file)
136135
}
@@ -164,7 +163,7 @@ mod tests {
164163
fn drop(&mut self) {
165164
// We test for invalid directory names, so it's OK if directory removal
166165
// fails.
167-
match fs::remove_dir_all(&self.path_to_channel_data) {
166+
match fs::remove_dir_all(&self.path_to_data) {
168167
Err(e) => println!("Failed to remove test persister directory: {}", e),
169168
_ => {}
170169
}
@@ -248,7 +247,7 @@ mod tests {
248247
#[test]
249248
fn test_readonly_dir_perm_failure() {
250249
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();
252251

253252
// Set up a dummy channel and force close. This will produce a monitor
254253
// that we can then use to test persistence.
@@ -266,7 +265,7 @@ mod tests {
266265
// Set the persister's directory to read-only, which should result in
267266
// returning a permanent failure when we then attempt to persist a
268267
// channel update.
269-
let path = &persister.path_to_channel_data;
268+
let path = &persister.path_to_data;
270269
let mut perms = fs::metadata(path).unwrap().permissions();
271270
perms.set_readonly(true);
272271
fs::set_permissions(path, perms).unwrap();

0 commit comments

Comments
 (0)