@@ -50,6 +50,38 @@ fn strip_verbatim_from_prefix(prefix: &PrefixComponent<'_>) -> Option<PathBuf> {
5050 Some ( ret)
5151}
5252
53+ #[ derive( Debug ) ]
54+ struct DirRemoveError {
55+ kind : std:: io:: ErrorKind ,
56+ path : String ,
57+ }
58+
59+ impl std:: error:: Error for DirRemoveError { }
60+
61+ impl std:: fmt:: Display for DirRemoveError {
62+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
63+ f. write_fmt ( format_args ! ( "failed to remove directory '{}' : {:?}" , self . path, self . kind) )
64+ }
65+ }
66+
67+ pub ( crate ) fn improve_remove_dir_error ( error : std:: io:: Error , path : & Path ) -> std:: io:: Error {
68+ std:: io:: Error :: new ( error. kind ( ) , DirRemoveError { kind : error. kind ( ) , path : path. display ( ) . to_string ( ) } )
69+ }
70+
71+ #[ test]
72+ fn custom_remove_dir_error ( ) {
73+
74+ let path = "test/path" . as_ref ( ) ;
75+
76+ let expected = "failed to remove directory 'test/path' : PermissionDenied" ;
77+ let tested = format ! ( "{}" , improve_remove_dir_error( std:: io:: Error :: from( std:: io:: ErrorKind :: PermissionDenied ) , path) ) ;
78+ assert_eq ! ( expected, tested) ;
79+
80+ let expected = "Custom { kind: PermissionDenied, error: DirRemoveError { kind: PermissionDenied, path: \" test/path\" } }" ;
81+ let tested = format ! ( "{:?}" , improve_remove_dir_error( std:: io:: Error :: from( std:: io:: ErrorKind :: PermissionDenied ) , path) ) ;
82+ assert_eq ! ( expected, tested) ;
83+ }
84+
5385pub ( crate ) fn normalize_path ( path : & Path ) -> PathBuf {
5486 let mut p = std:: fs:: canonicalize ( path) . unwrap_or_else ( |_| path. to_path_buf ( ) ) ;
5587
0 commit comments