Skip to content

Commit 1fa94f4

Browse files
committed
temp
1 parent 0f2fb2d commit 1fa94f4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ fn create_core_app() -> App<'static, 'static> {
337337
.subcommand(SubCommand::with_name("download-or-update-course-exercises")
338338
.about("Downloads exercises. If downloading an exercise that has been downloaded before, the student file policy will be used to avoid overwriting student files, effectively just updating the exercise files")
339339
.long_about(schema_leaked::<DownloadOrUpdateCourseExercisesResult>())
340+
.arg(Arg::with_name("download-from-template")
341+
.help("If set, will always download the course template instead of the latest submission, even if one exists.")
342+
.long("download-from-template"))
340343
.arg(Arg::with_name("exercise-id")
341344
.help("Exercise id of an exercise that should be downloaded. Multiple ids can be given.")
342345
.long("exercise-id")

tmc-langs-cli/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ fn run_core(
711711
print_output(&output, pretty)?
712712
}
713713
("download-or-update-course-exercises", Some(matches)) => {
714+
let download_from_template = matches.is_present("download-from-template");
715+
714716
let exercise_ids = matches.values_of("exercise-id").unwrap();
715717
let exercise_ids = exercise_ids
716718
.into_iter()
@@ -721,6 +723,7 @@ fn run_core(
721723
&client,
722724
client_name,
723725
&exercise_ids,
726+
download_from_template,
724727
)? {
725728
DownloadResult::Success {
726729
downloaded,

tmc-langs/src/lib.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)