@@ -20,7 +20,7 @@ fn find_ledger_dir(path_to_walk: &Path) -> Option<PathBuf> {
20
20
21
21
/// Represent an ledger file in a Cardano node database directory
22
22
#[ derive( Debug , PartialEq , Eq , Clone ) ]
23
- pub struct LedgerFile {
23
+ pub struct LedgerStateSnapshot {
24
24
/// The path to the ledger file
25
25
pub path : PathBuf ,
26
26
@@ -31,16 +31,16 @@ pub struct LedgerFile {
31
31
pub filename : String ,
32
32
}
33
33
34
- /// [LedgerFile ::list_all_in_dir] related errors.
34
+ /// [LedgerStateSnapshot ::list_all_in_dir] related errors.
35
35
#[ derive( Error , Debug ) ]
36
- pub enum LedgerFileListingError {
36
+ pub enum LedgerStateSnapshotListingError {
37
37
/// Raised when the "ledger" folder could not be found in a file structure.
38
38
#[ error( "Couldn't find the 'ledger' folder in '{0:?}'" ) ]
39
39
MissingLedgerFolder ( PathBuf ) ,
40
40
}
41
41
42
- impl LedgerFile {
43
- /// LedgerFile factory
42
+ impl LedgerStateSnapshot {
43
+ /// `LedgerStateSnapshot` factory
44
44
pub fn new < T : Into < String > > ( path : PathBuf , slot_number : SlotNumber , filename : T ) -> Self {
45
45
Self {
46
46
path,
@@ -49,11 +49,11 @@ impl LedgerFile {
49
49
}
50
50
}
51
51
52
- /// Convert a path to a LedgerFile if it satisfies the LedgerFile constraints.
52
+ /// Convert a path to a [LedgerStateSnapshot] if it satisfies the constraints.
53
53
///
54
54
/// The constraints are: the path must be a file, the filename should only contain a number (no
55
55
/// extension).
56
- pub fn from_path ( path : & Path ) -> Option < LedgerFile > {
56
+ pub fn from_path ( path : & Path ) -> Option < LedgerStateSnapshot > {
57
57
path. file_name ( )
58
58
. map ( |name| name. to_string_lossy ( ) )
59
59
. and_then ( |filename| {
@@ -64,12 +64,14 @@ impl LedgerFile {
64
64
} )
65
65
}
66
66
67
- /// List all [`LedgerFile`] in a given directory.
68
- pub fn list_all_in_dir ( dir : & Path ) -> Result < Vec < LedgerFile > , LedgerFileListingError > {
67
+ /// List all [`LedgerStateSnapshot`] in a given directory.
68
+ pub fn list_all_in_dir (
69
+ dir : & Path ,
70
+ ) -> Result < Vec < LedgerStateSnapshot > , LedgerStateSnapshotListingError > {
69
71
let ledger_dir = find_ledger_dir ( dir) . ok_or (
70
- LedgerFileListingError :: MissingLedgerFolder ( dir. to_path_buf ( ) ) ,
72
+ LedgerStateSnapshotListingError :: MissingLedgerFolder ( dir. to_path_buf ( ) ) ,
71
73
) ?;
72
- let mut files: Vec < LedgerFile > = vec ! [ ] ;
74
+ let mut files: Vec < LedgerStateSnapshot > = vec ! [ ] ;
73
75
74
76
for path in WalkDir :: new ( ledger_dir)
75
77
. min_depth ( 1 )
@@ -78,7 +80,7 @@ impl LedgerFile {
78
80
. filter_entry ( |e| e. file_type ( ) . is_file ( ) )
79
81
. filter_map ( |file| file. ok ( ) )
80
82
{
81
- if let Some ( ledger_file) = LedgerFile :: from_path ( path. path ( ) ) {
83
+ if let Some ( ledger_file) = LedgerStateSnapshot :: from_path ( path. path ( ) ) {
82
84
files. push ( ledger_file) ;
83
85
}
84
86
}
@@ -88,13 +90,13 @@ impl LedgerFile {
88
90
}
89
91
}
90
92
91
- impl PartialOrd for LedgerFile {
93
+ impl PartialOrd for LedgerStateSnapshot {
92
94
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
93
95
Some ( self . cmp ( other) )
94
96
}
95
97
}
96
98
97
- impl Ord for LedgerFile {
99
+ impl Ord for LedgerStateSnapshot {
98
100
fn cmp ( & self , other : & Self ) -> Ordering {
99
101
self . slot_number
100
102
. cmp ( & other. slot_number )
@@ -110,7 +112,7 @@ mod tests {
110
112
111
113
use crate :: test_utils:: TempDir ;
112
114
113
- use super :: LedgerFile ;
115
+ use super :: LedgerStateSnapshot ;
114
116
115
117
fn get_test_dir ( subdir_name : & str ) -> PathBuf {
116
118
TempDir :: create ( "ledger_file" , subdir_name)
@@ -124,7 +126,7 @@ mod tests {
124
126
}
125
127
}
126
128
127
- fn extract_filenames ( ledger_files : & [ LedgerFile ] ) -> Vec < String > {
129
+ fn extract_filenames ( ledger_files : & [ LedgerStateSnapshot ] ) -> Vec < String > {
128
130
ledger_files
129
131
. iter ( )
130
132
. map ( |i| i. path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) )
@@ -137,15 +139,15 @@ mod tests {
137
139
let entries = vec ! [ ] ;
138
140
create_fake_files ( & target_dir, & entries) ;
139
141
140
- LedgerFile :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
141
- . expect_err ( "LedgerFile ::list_all_in_dir should have Failed" ) ;
142
+ LedgerStateSnapshot :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
143
+ . expect_err ( "LedgerStateSnapshot ::list_all_in_dir should have Failed" ) ;
142
144
}
143
145
144
146
#[ test]
145
147
fn list_all_ledger_file_should_works_in_a_empty_folder ( ) {
146
148
let target_dir = get_test_dir ( "list_all_ledger_file_should_works_in_a_empty_folder/ledger" ) ;
147
- let result = LedgerFile :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
148
- . expect ( "LedgerFile ::list_all_in_dir should work in a empty folder" ) ;
149
+ let result = LedgerStateSnapshot :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
150
+ . expect ( "LedgerStateSnapshot ::list_all_in_dir should work in a empty folder" ) ;
149
151
150
152
assert ! ( result. is_empty( ) ) ;
151
153
}
@@ -155,8 +157,8 @@ mod tests {
155
157
let target_dir = get_test_dir ( "list_all_ledger_file_order_should_be_deterministic/ledger" ) ;
156
158
let entries = vec ! [ "424" , "123" , "124" , "00125" , "21" , "223" , "0423" ] ;
157
159
create_fake_files ( & target_dir, & entries) ;
158
- let ledger_files = LedgerFile :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
159
- . expect ( "LedgerFile ::list_all_in_dir Failed" ) ;
160
+ let ledger_files = LedgerStateSnapshot :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
161
+ . expect ( "LedgerStateSnapshot ::list_all_in_dir Failed" ) ;
160
162
161
163
assert_eq ! (
162
164
vec![ "21" , "123" , "124" , "00125" , "223" , "0423" , "424" ] ,
@@ -170,8 +172,8 @@ mod tests {
170
172
get_test_dir ( "list_all_ledger_file_should_work_with_non_ledger_files/ledger" ) ;
171
173
let entries = vec ! [ "123" , "124" , "README.md" , "124.back" ] ;
172
174
create_fake_files ( & target_dir, & entries) ;
173
- let ledger_files = LedgerFile :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
174
- . expect ( "LedgerFile ::list_all_in_dir Failed" ) ;
175
+ let ledger_files = LedgerStateSnapshot :: list_all_in_dir ( target_dir. parent ( ) . unwrap ( ) )
176
+ . expect ( "LedgerStateSnapshot ::list_all_in_dir Failed" ) ;
175
177
176
178
assert_eq ! ( vec![ "123" , "124" ] , extract_filenames( & ledger_files) ) ;
177
179
}
0 commit comments