11use super :: {
2- DeduplicateSharedSize , HardlinkList , LinkPathList , RecordHardlinks , RecordHardlinksArgument ,
2+ hardlink_list, DeduplicateSharedSize , HardlinkList , LinkPathList , RecordHardlinks ,
3+ RecordHardlinksArgument ,
34} ;
45use crate :: {
56 data_tree:: DataTree ,
@@ -8,7 +9,7 @@ use crate::{
89 reporter:: { event:: HardlinkDetection , Event , Reporter } ,
910 size,
1011} ;
11- use derive_more:: { AsMut , AsRef , From , Into } ;
12+ use derive_more:: { AsMut , AsRef , Display , Error , From , Into } ;
1213use pipe_trait:: Pipe ;
1314use smart_default:: SmartDefault ;
1415use std:: { convert:: Infallible , fmt:: Debug , os:: unix:: fs:: MetadataExt , path:: Path } ;
@@ -37,12 +38,26 @@ impl<Size> Aware<Size> {
3738 }
3839}
3940
41+ /// Error that occurs when [`Aware::record_hardlinks`] fails.
42+ #[ derive( Debug , Display , Error ) ]
43+ #[ non_exhaustive]
44+ pub enum ReportHardlinksError < Size > {
45+ /// Fail to add an entry to the record.
46+ #[ display( "Fail to add an entry to record: {_0}" ) ]
47+ AddToRecord ( hardlink_list:: AddError < Size > ) ,
48+ }
49+
4050impl < Size , Report > RecordHardlinks < Size , Report > for Aware < Size >
4151where
4252 Size : size:: Size + Eq + Debug ,
4353 Report : Reporter < Size > + ?Sized ,
4454{
45- fn record_hardlinks ( & self , argument : RecordHardlinksArgument < Size , Report > ) {
55+ type Error = ReportHardlinksError < Size > ;
56+
57+ fn record_hardlinks (
58+ & self ,
59+ argument : RecordHardlinksArgument < Size , Report > ,
60+ ) -> Result < ( ) , Self :: Error > {
4661 let RecordHardlinksArgument {
4762 path,
4863 stats,
@@ -51,12 +66,12 @@ where
5166 } = argument;
5267
5368 if stats. is_dir ( ) {
54- return ;
69+ return Ok ( ( ) ) ;
5570 }
5671
5772 let links = stats. nlink ( ) ;
5873 if links <= 1 {
59- return ;
74+ return Ok ( ( ) ) ;
6075 }
6176
6277 reporter. report ( Event :: DetectHardlink ( HardlinkDetection {
6782 } ) ) ;
6883
6984 let ino = InodeNumber :: get ( stats) ;
70- self . record . add ( ino, size, path) . unwrap ( ) ; // TODO: propagate the error
85+ self . record
86+ . add ( ino, size, path)
87+ . map_err ( ReportHardlinksError :: AddToRecord )
7188 }
7289}
7390
0 commit comments