@@ -20,7 +20,7 @@ fn find_ledger_dir(path_to_walk: &Path) -> Option<PathBuf> {
2020
2121/// Represent an ledger file in a Cardano node database directory
2222#[ derive( Debug , PartialEq , Eq , Clone ) ]
23- pub struct LedgerFile {
23+ pub struct LedgerStateSnapshot {
2424 /// The path to the ledger file
2525 pub path : PathBuf ,
2626
@@ -31,16 +31,16 @@ pub struct LedgerFile {
3131 pub filename : String ,
3232}
3333
34- /// [LedgerFile ::list_all_in_dir] related errors.
34+ /// [LedgerStateSnapshot ::list_all_in_dir] related errors.
3535#[ derive( Error , Debug ) ]
36- pub enum LedgerFileListingError {
36+ pub enum LedgerStateSnapshotListingError {
3737 /// Raised when the "ledger" folder could not be found in a file structure.
3838 #[ error( "Couldn't find the 'ledger' folder in '{0:?}'" ) ]
3939 MissingLedgerFolder ( PathBuf ) ,
4040}
4141
42- impl LedgerFile {
43- /// LedgerFile factory
42+ impl LedgerStateSnapshot {
43+ /// `LedgerStateSnapshot` factory
4444 pub fn new < T : Into < String > > ( path : PathBuf , slot_number : SlotNumber , filename : T ) -> Self {
4545 Self {
4646 path,
@@ -49,11 +49,11 @@ impl LedgerFile {
4949 }
5050 }
5151
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.
5353 ///
5454 /// The constraints are: the path must be a file, the filename should only contain a number (no
5555 /// extension).
56- pub fn from_path ( path : & Path ) -> Option < LedgerFile > {
56+ pub fn from_path ( path : & Path ) -> Option < LedgerStateSnapshot > {
5757 path. file_name ( )
5858 . map ( |name| name. to_string_lossy ( ) )
5959 . and_then ( |filename| {
@@ -64,12 +64,14 @@ impl LedgerFile {
6464 } )
6565 }
6666
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 > {
6971 let ledger_dir = find_ledger_dir ( dir) . ok_or (
70- LedgerFileListingError :: MissingLedgerFolder ( dir. to_path_buf ( ) ) ,
72+ LedgerStateSnapshotListingError :: MissingLedgerFolder ( dir. to_path_buf ( ) ) ,
7173 ) ?;
72- let mut files: Vec < LedgerFile > = vec ! [ ] ;
74+ let mut files: Vec < LedgerStateSnapshot > = vec ! [ ] ;
7375
7476 for path in WalkDir :: new ( ledger_dir)
7577 . min_depth ( 1 )
@@ -78,7 +80,7 @@ impl LedgerFile {
7880 . filter_entry ( |e| e. file_type ( ) . is_file ( ) )
7981 . filter_map ( |file| file. ok ( ) )
8082 {
81- if let Some ( ledger_file) = LedgerFile :: from_path ( path. path ( ) ) {
83+ if let Some ( ledger_file) = LedgerStateSnapshot :: from_path ( path. path ( ) ) {
8284 files. push ( ledger_file) ;
8385 }
8486 }
@@ -88,13 +90,13 @@ impl LedgerFile {
8890 }
8991}
9092
91- impl PartialOrd for LedgerFile {
93+ impl PartialOrd for LedgerStateSnapshot {
9294 fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
9395 Some ( self . cmp ( other) )
9496 }
9597}
9698
97- impl Ord for LedgerFile {
99+ impl Ord for LedgerStateSnapshot {
98100 fn cmp ( & self , other : & Self ) -> Ordering {
99101 self . slot_number
100102 . cmp ( & other. slot_number )
@@ -110,7 +112,7 @@ mod tests {
110112
111113 use crate :: test_utils:: TempDir ;
112114
113- use super :: LedgerFile ;
115+ use super :: LedgerStateSnapshot ;
114116
115117 fn get_test_dir ( subdir_name : & str ) -> PathBuf {
116118 TempDir :: create ( "ledger_file" , subdir_name)
@@ -124,7 +126,7 @@ mod tests {
124126 }
125127 }
126128
127- fn extract_filenames ( ledger_files : & [ LedgerFile ] ) -> Vec < String > {
129+ fn extract_filenames ( ledger_files : & [ LedgerStateSnapshot ] ) -> Vec < String > {
128130 ledger_files
129131 . iter ( )
130132 . map ( |i| i. path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) )
@@ -137,15 +139,15 @@ mod tests {
137139 let entries = vec ! [ ] ;
138140 create_fake_files ( & target_dir, & entries) ;
139141
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" ) ;
142144 }
143145
144146 #[ test]
145147 fn list_all_ledger_file_should_works_in_a_empty_folder ( ) {
146148 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" ) ;
149151
150152 assert ! ( result. is_empty( ) ) ;
151153 }
@@ -155,8 +157,8 @@ mod tests {
155157 let target_dir = get_test_dir ( "list_all_ledger_file_order_should_be_deterministic/ledger" ) ;
156158 let entries = vec ! [ "424" , "123" , "124" , "00125" , "21" , "223" , "0423" ] ;
157159 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" ) ;
160162
161163 assert_eq ! (
162164 vec![ "21" , "123" , "124" , "00125" , "223" , "0423" , "424" ] ,
@@ -170,8 +172,8 @@ mod tests {
170172 get_test_dir ( "list_all_ledger_file_should_work_with_non_ledger_files/ledger" ) ;
171173 let entries = vec ! [ "123" , "124" , "README.md" , "124.back" ] ;
172174 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" ) ;
175177
176178 assert_eq ! ( vec![ "123" , "124" ] , extract_filenames( & ledger_files) ) ;
177179 }
0 commit comments