@@ -311,19 +311,21 @@ fn accept_item(
311311 } ;
312312
313313 if let Err ( error) = fs:: remove_file ( & path) {
314- let _ = fs:: remove_file ( vault_root. join ( & raw_path) ) ;
314+ let mut cleanup_errors = Vec :: new ( ) ;
315+ cleanup_collect_file ( vault_root, & raw_path, & mut cleanup_errors) ;
315316 if let Some ( asset_path) = & asset_path {
316- let _ = fs :: remove_file ( vault_root. join ( asset_path) ) ;
317+ cleanup_collect_file ( vault_root, asset_path, & mut cleanup_errors ) ;
317318 }
318319 let original_error = io_error ( "remove accepted inbox item" , & path, error) ;
319320 if let Err ( rollback_error) = previous_manifest. write ( vault_root) {
320321 return Err ( WikiError :: Config {
321322 detail : format ! (
322- "failed to roll back source manifest after inbox removal failed: {rollback_error}; original error: {original_error}"
323+ "failed to roll back source manifest after inbox removal failed: {rollback_error}; original error: {original_error}{}" ,
324+ collect_cleanup_detail( & cleanup_errors)
323325 ) ,
324326 } ) ;
325327 }
326- return Err ( original_error) ;
328+ return collect_error_with_cleanup ( original_error, cleanup_errors ) ;
327329 }
328330 report. accepted . push ( CollectAction {
329331 inbox_path : relative,
@@ -342,20 +344,54 @@ fn rollback_registered_collect_source<T>(
342344 asset_path : Option < & PathBuf > ,
343345 original_error : WikiError ,
344346) -> Result < T , WikiError > {
347+ let mut cleanup_errors = Vec :: new ( ) ;
345348 if let Some ( raw_path) = raw_path {
346- let _ = fs :: remove_file ( vault_root. join ( raw_path) ) ;
349+ cleanup_collect_file ( vault_root, raw_path, & mut cleanup_errors ) ;
347350 }
348351 if let Some ( asset_path) = asset_path {
349- let _ = fs :: remove_file ( vault_root. join ( asset_path) ) ;
352+ cleanup_collect_file ( vault_root, asset_path, & mut cleanup_errors ) ;
350353 }
351354 if let Err ( rollback_error) = previous_manifest. write ( vault_root) {
352355 return Err ( WikiError :: Config {
353356 detail : format ! (
354- "failed to roll back source manifest after collect write failure: {rollback_error}; original error: {original_error}"
357+ "failed to roll back source manifest after collect write failure: {rollback_error}; original error: {original_error}{}" ,
358+ collect_cleanup_detail( & cleanup_errors)
355359 ) ,
356360 } ) ;
357361 }
358- Err ( original_error)
362+ collect_error_with_cleanup ( original_error, cleanup_errors)
363+ }
364+
365+ fn cleanup_collect_file ( vault_root : & Path , relative_path : & Path , cleanup_errors : & mut Vec < String > ) {
366+ let path = vault_root. join ( relative_path) ;
367+ match fs:: remove_file ( & path) {
368+ Ok ( ( ) ) => { }
369+ Err ( error) if error. kind ( ) == std:: io:: ErrorKind :: NotFound => { }
370+ Err ( error) => cleanup_errors. push ( format ! ( "{}: {error}" , path. display( ) ) ) ,
371+ }
372+ }
373+
374+ fn collect_error_with_cleanup < T > (
375+ original_error : WikiError ,
376+ cleanup_errors : Vec < String > ,
377+ ) -> Result < T , WikiError > {
378+ if cleanup_errors. is_empty ( ) {
379+ return Err ( original_error) ;
380+ }
381+ Err ( WikiError :: Config {
382+ detail : format ! (
383+ "{original_error}; cleanup failures: {}" ,
384+ cleanup_errors. join( "; " )
385+ ) ,
386+ } )
387+ }
388+
389+ fn collect_cleanup_detail ( cleanup_errors : & [ String ] ) -> String {
390+ if cleanup_errors. is_empty ( ) {
391+ String :: new ( )
392+ } else {
393+ format ! ( "; cleanup failures: {}" , cleanup_errors. join( "; " ) )
394+ }
359395}
360396
361397fn skip_item (
0 commit comments