@@ -119,26 +119,30 @@ pub fn download_or_update_course_exercises(
119119 client : & TmcClient ,
120120 client_name : & str ,
121121 exercises : & [ usize ] ,
122+ download_from_template : bool ,
122123) -> Result < DownloadResult , LangsError > {
123124 let exercises_details = client. get_exercises_details ( exercises) ?;
124125
125126 let config_path = TmcConfig :: get_location ( client_name) ?;
126127 let projects_dir = TmcConfig :: load ( client_name, & config_path) ?. projects_dir ;
127128 let mut projects_config = ProjectsConfig :: load ( & projects_dir) ?;
128129
129- // separate downloads into ones that don't need to be downloaded and ones that do
130- let mut to_be_downloaded = HashMap :: new ( ) ;
130+ // separate exercises into fresh downloads, submission downloads and skipped
131+ let mut to_be_downloaded_fresh = HashMap :: new ( ) ;
132+ let mut to_be_downloaded_submission = HashMap :: new ( ) ;
131133 let mut to_be_skipped = vec ! [ ] ;
134+
132135 for exercise_detail in exercises_details {
133136 let target = ProjectsConfig :: get_exercise_download_target (
134137 & projects_dir,
135138 & exercise_detail. course_name ,
136139 & exercise_detail. exercise_name ,
137140 ) ;
138141
139- // check if the checksum is different from what's already on disk
142+ // check if the exercise is already on disk
140143 if let Some ( course_config) = projects_config. courses . get ( & exercise_detail. course_name ) {
141144 if let Some ( exercise) = course_config. exercises . get ( & exercise_detail. exercise_name ) {
145+ // exercise is on disk, check if the checksum is identical
142146 if exercise_detail. checksum == exercise. checksum {
143147 // skip this exercise
144148 log:: info!(
@@ -153,6 +157,23 @@ pub fn download_or_update_course_exercises(
153157 path : target,
154158 } ) ;
155159 continue ;
160+ } else if !download_from_template {
161+ // different checksum, if flag isn't set check if there are any previous submissions
162+ if let Some ( latest_submission) = client
163+ . get_exercise_submissions_for_current_user ( exercise. id ) ?
164+ . first ( )
165+ {
166+ // previous submission found
167+ to_be_downloaded_submission. insert (
168+ exercise_detail. id ,
169+ ExerciseDownload {
170+ course_slug : exercise_detail. exercise_name . clone ( ) ,
171+ exercise_slug : exercise_detail. exercise_name . clone ( ) ,
172+ path : target,
173+ } ,
174+ ) ;
175+ continue ;
176+ }
156177 }
157178 }
158179 }
0 commit comments