@@ -303,7 +303,7 @@ impl Snapshot {
303
303
/// - `path` does not refer to a readable file.
304
304
/// - The file at `path` is corrupted,
305
305
/// as detected by comparing the hash of its bytes to a hash recorded in the file.
306
- fn read_from_file ( path : & Path ) -> Result < Self , SnapshotError > {
306
+ pub fn read_from_file ( path : & Path ) -> Result < Self , SnapshotError > {
307
307
let err_read_object = |cause| SnapshotError :: ReadObject {
308
308
ty : ObjectType :: Snapshot ,
309
309
source_repo : path. to_path_buf ( ) ,
@@ -562,17 +562,53 @@ impl SnapshotRepository {
562
562
}
563
563
}
564
564
565
- fn snapshot_dir_path ( & self , tx_offset : TxOffset ) -> PathBuf {
565
+ /// Get the path to the directory which would contain the snapshot of transaction `tx_offset`.
566
+ ///
567
+ /// The directory may not exist if no snapshot has been taken of `tx_offset`.
568
+ ///
569
+ /// The directory may exist but be locked or incomplete
570
+ /// if a file with the same name and the extension `.lock` exists.
571
+ /// In this case, callers should treat the snapshot as if it did not exist.
572
+ ///
573
+ /// Use `[Self::all_snapshots]` to get `tx_offsets` which will return valid extant paths.
574
+ /// `[Self::all_snapshots]` will never return a `tx_offset` for a locked or incomplete snapshot.
575
+ /// `[Self::all_snapshots]` does not validate the contents of snapshots,
576
+ /// so it may return a `tx_offset` whose snapshot is corrupted.
577
+ ///
578
+ /// Any mutations to any files contained in the returned directory
579
+ /// will likely corrupt the snapshot,
580
+ /// causing attempts to reconstruct it to fail.
581
+ pub fn snapshot_dir_path ( & self , tx_offset : TxOffset ) -> PathBuf {
566
582
let dir_name = format ! ( "{tx_offset:0>20}.{SNAPSHOT_DIR_EXT}" ) ;
567
583
self . root . join ( dir_name)
568
584
}
569
585
570
- fn snapshot_file_path ( tx_offset : TxOffset , snapshot_dir : & Path ) -> PathBuf {
586
+ /// Given `snapshot_dir` as the result of `self.snapshot_dir_path(tx_offset)`,
587
+ /// get the path to the root snapshot file, which contains a serialized [`Snapshot`].
588
+ ///
589
+ /// This method does not validate that the `snapshot_dir` exists or is valid,
590
+ /// so the returned snapshot file path may be nonexistant or refer to a locked or incomplete snapshot file.
591
+ /// This method also does not check if the snapshot file, or any other part of the snapshot, is corrupted.
592
+ /// Consumers should verify the hashes stored in the snapshot file and object repository.
593
+ ///
594
+ /// Any mutations to the snapshot file will likely render the snapshot corrupted,
595
+ /// causing future attempts to reconstruct it to fail.
596
+ pub fn snapshot_file_path ( tx_offset : TxOffset , snapshot_dir : & Path ) -> PathBuf {
571
597
let file_name = format ! ( "{tx_offset:0>20}.{SNAPSHOT_FILE_EXT}" ) ;
572
598
snapshot_dir. join ( file_name)
573
599
}
574
600
575
- fn object_repo ( snapshot_dir : & Path ) -> Result < DirTrie , std:: io:: Error > {
601
+ /// Given `snapshot_dir` as the result of [`Self::snapshot_dir_path`],
602
+ /// get the [`DirTrie`] which contains serialized objects (pages and large blobs)
603
+ /// referenced by the [`Snapshot`] contained in the [`Self::snapshot_file_path`].
604
+ ///
605
+ /// Consequences are unspecified if this method is called from outside this crate
606
+ /// on a non-existent, locked or incomplete `snapshot_dir`.
607
+ ///
608
+ /// Any mutations to the returned [`DirTrie`] or its contents
609
+ /// will likely render the snapshot corrupted,
610
+ /// causing future attempts to reconstruct it to fail.
611
+ pub fn object_repo ( snapshot_dir : & Path ) -> Result < DirTrie , std:: io:: Error > {
576
612
DirTrie :: open ( snapshot_dir. join ( "objects" ) )
577
613
}
578
614
0 commit comments