@@ -24,16 +24,11 @@ pub fn run_clean(ctx: &WorkspaceContext, cache: bool, backups: bool, reports: bo
2424 . join ( "target" )
2525 . join ( "cargo-rail" )
2626 . join ( "metadata.json" ) ;
27- let old_cache = ctx. workspace_root . join ( "target" ) . join ( "rail" ) ;
2827
2928 if cache_path. exists ( ) {
3029 println ! ( " {}" , cache_path. display( ) ) ;
3130 would_clean = true ;
3231 }
33- if old_cache. exists ( ) {
34- println ! ( " {} (legacy)" , old_cache. display( ) ) ;
35- would_clean = true ;
36- }
3732 }
3833
3934 if clean_reports {
@@ -111,23 +106,20 @@ pub fn run_clean(ctx: &WorkspaceContext, cache: bool, backups: bool, reports: bo
111106}
112107
113108fn clean_metadata_cache ( ctx : & WorkspaceContext ) -> RailResult < ( ) > {
114- let rail_target = ctx
109+ let cache_path = ctx
115110 . workspace_root
116111 . join ( "target" )
117112 . join ( "cargo-rail" )
118113 . join ( "metadata.json" ) ;
119- let old_rail_target = ctx. workspace_root . join ( "target" ) . join ( "rail" ) ;
120114
121- if rail_target . exists ( ) {
115+ if cache_path . exists ( ) {
122116 progress ! ( "removing cache..." ) ;
123- fs:: remove_file ( & rail_target)
124- . map_err ( |e| RailError :: message ( format ! ( "failed to remove {}: {}" , rail_target. display( ) , e) ) ) ?;
125- }
126-
127- if old_rail_target. exists ( ) {
128- progress ! ( "removing legacy cache..." ) ;
129- fs:: remove_dir_all ( & old_rail_target)
130- . map_err ( |e| RailError :: message ( format ! ( "failed to remove {}: {}" , old_rail_target. display( ) , e) ) ) ?;
117+ fs:: remove_file ( & cache_path) . map_err ( |e| {
118+ RailError :: with_help (
119+ format ! ( "failed to remove {}: {}" , cache_path. display( ) , e) ,
120+ "check file permissions or if the file is in use" ,
121+ )
122+ } ) ?;
131123 }
132124
133125 Ok ( ( ) )
@@ -138,12 +130,26 @@ fn clean_generated_reports(ctx: &WorkspaceContext) -> RailResult<()> {
138130
139131 if report_dir. exists ( ) {
140132 progress ! ( "removing reports..." ) ;
141- for entry in fs:: read_dir ( & report_dir) . map_err ( |e| RailError :: message ( format ! ( "failed to read dir: {}" , e) ) ) ? {
142- let entry = entry. map_err ( |e| RailError :: message ( format ! ( "failed to read entry: {}" , e) ) ) ?;
133+ for entry in fs:: read_dir ( & report_dir) . map_err ( |e| {
134+ RailError :: with_help (
135+ format ! ( "failed to read {}: {}" , report_dir. display( ) , e) ,
136+ "check directory permissions" ,
137+ )
138+ } ) ? {
139+ let entry = entry. map_err ( |e| {
140+ RailError :: with_help (
141+ format ! ( "failed to read directory entry: {}" , e) ,
142+ "check directory permissions" ,
143+ )
144+ } ) ?;
143145 let path = entry. path ( ) ;
144146 if path. is_file ( ) && path. extension ( ) . is_some_and ( |ext| ext == "md" ) {
145- fs:: remove_file ( & path)
146- . map_err ( |e| RailError :: message ( format ! ( "failed to remove {}: {}" , path. display( ) , e) ) ) ?;
147+ fs:: remove_file ( & path) . map_err ( |e| {
148+ RailError :: with_help (
149+ format ! ( "failed to remove {}: {}" , path. display( ) , e) ,
150+ "check file permissions or if the file is in use" ,
151+ )
152+ } ) ?;
147153 }
148154 }
149155 }
0 commit comments