8
8
9
9
use std:: fs;
10
10
use std:: fs:: FileType ;
11
+ use std:: io;
11
12
use std:: sync:: Arc ;
12
13
13
14
use crate :: ZoneImageZpools ;
@@ -177,7 +178,7 @@ fn read_mupdate_override(
177
178
fs:: symlink_metadata ( dataset_dir) . map_err ( |error| {
178
179
MupdateOverrideReadError :: DatasetDirMetadata {
179
180
dataset_dir : dataset_dir. to_owned ( ) ,
180
- error : Arc :: new ( error) ,
181
+ error : ArcIoError :: new ( error) ,
181
182
}
182
183
} ) ?;
183
184
if !dir_metadata. is_dir ( ) {
@@ -193,7 +194,7 @@ fn read_mupdate_override(
193
194
. map_err ( |error| {
194
195
MupdateOverrideReadError :: Deserialize {
195
196
path : override_path. to_owned ( ) ,
196
- error : Arc :: new ( error) ,
197
+ error : ArcSerdeJsonError :: new ( error) ,
197
198
contents : data,
198
199
}
199
200
} ) ?;
@@ -210,7 +211,7 @@ fn read_mupdate_override(
210
211
} else {
211
212
return Err ( MupdateOverrideReadError :: Read {
212
213
path : override_path. to_owned ( ) ,
213
- error : Arc :: new ( error) ,
214
+ error : ArcIoError :: new ( error) ,
214
215
} ) ;
215
216
}
216
217
}
@@ -398,7 +399,7 @@ impl MupdateOverrideNonBootMismatch {
398
399
}
399
400
}
400
401
401
- #[ derive( Clone , Debug , Error ) ]
402
+ #[ derive( Clone , Debug , Error , PartialEq ) ]
402
403
enum MupdateOverrideReadError {
403
404
#[ error(
404
405
"error retrieving metadata for install dataset directory \
@@ -407,7 +408,7 @@ enum MupdateOverrideReadError {
407
408
DatasetDirMetadata {
408
409
dataset_dir : Utf8PathBuf ,
409
410
#[ source]
410
- error : Arc < std :: io :: Error > ,
411
+ error : ArcIoError ,
411
412
} ,
412
413
413
414
#[ error(
@@ -420,7 +421,7 @@ enum MupdateOverrideReadError {
420
421
Read {
421
422
path : Utf8PathBuf ,
422
423
#[ source]
423
- error : Arc < std :: io :: Error > ,
424
+ error : ArcIoError ,
424
425
} ,
425
426
426
427
#[ error(
@@ -431,67 +432,47 @@ enum MupdateOverrideReadError {
431
432
path : Utf8PathBuf ,
432
433
contents : String ,
433
434
#[ source]
434
- error : Arc < serde_json :: Error > ,
435
+ error : ArcSerdeJsonError ,
435
436
} ,
436
437
}
437
438
438
- /// This aids tremendously in testing.
439
- ///
440
- /// `MupdateOverrideReadError` forms an equivalence class (i.e. it satisfies the
441
- /// reflexive property `a == a`), so it should in principle be okay to implement
442
- /// `Eq` for it as well. But this algorithm doesn't fully compare for equality,
443
- /// just enough for tests, so we don't implement `Eq`.
444
- ///
445
- /// (But if there's a use case for `Eq` in the future, we should consider
446
- /// implementing it.)
447
- impl PartialEq for MupdateOverrideReadError {
439
+ /// An `io::Error` wrapper that implements `Clone` and `PartialEq`.
440
+ #[ derive( Clone , Debug , Error ) ]
441
+ #[ error( transparent) ]
442
+ struct ArcIoError ( Arc < io:: Error > ) ;
443
+
444
+ impl ArcIoError {
445
+ fn new ( error : io:: Error ) -> Self {
446
+ Self ( Arc :: new ( error) )
447
+ }
448
+ }
449
+
450
+ /// Testing aid.
451
+ impl PartialEq for ArcIoError {
448
452
fn eq ( & self , other : & Self ) -> bool {
449
- match ( self , other) {
450
- (
451
- Self :: DatasetDirMetadata { dataset_dir : dir1, error : error1 } ,
452
- Self :: DatasetDirMetadata { dataset_dir : dir2, error : error2 } ,
453
- ) => {
454
- // Simply comparing io::ErrorKind is good enough for tests.
455
- dir1 == dir2 && error1. kind ( ) == error2. kind ( )
456
- }
457
- (
458
- Self :: DatasetNotDirectory {
459
- dataset_dir : dir1,
460
- file_type : type1,
461
- } ,
462
- Self :: DatasetNotDirectory {
463
- dataset_dir : dir2,
464
- file_type : type2,
465
- } ,
466
- ) => dir1 == dir2 && type1 == type2,
467
- (
468
- Self :: Read { path : path1, error : error1 } ,
469
- Self :: Read { path : path2, error : error2 } ,
470
- ) => {
471
- // Simply comparing io::ErrorKind is good enough for tests.
472
- path1 == path2 && error1. kind ( ) == error2. kind ( )
473
- }
474
- (
475
- Self :: Deserialize {
476
- path : path1,
477
- contents : contents1,
478
- error : error1,
479
- } ,
480
- Self :: Deserialize {
481
- path : path2,
482
- contents : contents2,
483
- error : error2,
484
- } ,
485
- ) => {
486
- // Comparing error line/column/category is enough for tests.
487
- path1 == path2
488
- && contents1 == contents2
489
- && error1. line ( ) == error2. line ( )
490
- && error1. column ( ) == error2. column ( )
491
- && error1. classify ( ) == error2. classify ( )
492
- }
493
- _ => false ,
494
- }
453
+ // Simply comparing io::ErrorKind is good enough for tests.
454
+ self . 0 . kind ( ) == other. 0 . kind ( )
455
+ }
456
+ }
457
+
458
+ /// A `serde_json::Error` that implements `Clone` and `PartialEq`.
459
+ #[ derive( Clone , Debug , Error ) ]
460
+ #[ error( transparent) ]
461
+ struct ArcSerdeJsonError ( Arc < serde_json:: Error > ) ;
462
+
463
+ impl ArcSerdeJsonError {
464
+ fn new ( error : serde_json:: Error ) -> Self {
465
+ Self ( Arc :: new ( error) )
466
+ }
467
+ }
468
+
469
+ /// Testing aid.
470
+ impl PartialEq for ArcSerdeJsonError {
471
+ fn eq ( & self , other : & Self ) -> bool {
472
+ // Simply comparing line/column/category is good enough for tests.
473
+ self . 0 . line ( ) == other. 0 . line ( )
474
+ && self . 0 . column ( ) == other. 0 . column ( )
475
+ && self . 0 . classify ( ) == other. 0 . classify ( )
495
476
}
496
477
}
497
478
@@ -983,7 +964,9 @@ mod tests {
983
964
fn dataset_missing_error ( dir_path : & Utf8Path ) -> MupdateOverrideReadError {
984
965
MupdateOverrideReadError :: DatasetDirMetadata {
985
966
dataset_dir : dir_path. to_owned ( ) ,
986
- error : Arc :: new ( io:: Error :: from ( io:: ErrorKind :: NotFound ) ) ,
967
+ error : ArcIoError ( Arc :: new ( io:: Error :: from (
968
+ io:: ErrorKind :: NotFound ,
969
+ ) ) ) ,
987
970
}
988
971
}
989
972
@@ -1007,10 +990,10 @@ mod tests {
1007
990
MupdateOverrideReadError :: Deserialize {
1008
991
path : dir_path. join ( json_path) ,
1009
992
contents : contents. to_owned ( ) ,
1010
- error : Arc :: new (
993
+ error : ArcSerdeJsonError ( Arc :: new (
1011
994
serde_json:: from_str :: < MupdateOverrideInfo > ( contents)
1012
995
. unwrap_err ( ) ,
1013
- ) ,
996
+ ) ) ,
1014
997
}
1015
998
}
1016
999
}
0 commit comments