@@ -24,6 +24,7 @@ use std::thread;
2424use std:: time:: Duration ;
2525use tempfile:: NamedTempFile ;
2626use tmc_langs_util:: task_executor;
27+ use walkdir:: WalkDir ;
2728
2829pub type Token =
2930 oauth2:: StandardTokenResponse < oauth2:: EmptyExtraTokenFields , oauth2:: basic:: BasicTokenType > ;
@@ -493,15 +494,29 @@ impl TmcCore {
493494 }
494495
495496 pub fn reset ( & self , exercise_id : usize , exercise_path : & Path ) -> Result < ( ) > {
496- // windows sometimes fails due to files being in use, retry a few times
497- // todo: handle properly
497+ // clear out the exercise directory
498498 let mut tries = 0 ;
499- while let Err ( err) = fs:: remove_dir_all ( exercise_path) {
500- tries += 1 ;
501- if tries > 8 {
502- return Err ( CoreError :: DirRemove ( exercise_path. to_path_buf ( ) , err) ) ;
499+ for entry in WalkDir :: new ( exercise_path) . min_depth ( 1 ) {
500+ let entry = entry?;
501+ // windows sometimes fails due to files being in use, retry a few times
502+ // todo: handle properly
503+ if entry. path ( ) . is_dir ( ) {
504+ while let Err ( err) = fs:: remove_dir_all ( exercise_path) {
505+ tries += 1 ;
506+ if tries > 8 {
507+ return Err ( CoreError :: DirRemove ( exercise_path. to_path_buf ( ) , err) ) ;
508+ }
509+ thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
510+ }
511+ } else {
512+ while let Err ( err) = fs:: remove_file ( exercise_path) {
513+ tries += 1 ;
514+ if tries > 8 {
515+ return Err ( CoreError :: DirRemove ( exercise_path. to_path_buf ( ) , err) ) ;
516+ }
517+ thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
518+ }
503519 }
504- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
505520 }
506521 self . download_or_update_exercises ( vec ! [ ( exercise_id, exercise_path) ] )
507522 }
0 commit comments