Skip to content

Commit ee370d4

Browse files
committed
make zip generic instead of dyn
1 parent 32637e5 commit ee370d4

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

tmc-langs-core/src/tmc_core.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,16 @@ impl TmcCore {
479479
}
480480

481481
pub fn reset(&self, exercise_id: usize, exercise_path: &Path) -> Result<()> {
482-
fs::remove_dir_all(exercise_path)
483-
.map_err(|e| CoreError::DirRemove(exercise_path.to_path_buf(), e))?;
482+
// windows sometimes fails due to files being in use, retry a few times
483+
// todo: handle properly
484+
let mut tries = 0;
485+
while let Err(err) = fs::remove_dir_all(exercise_path) {
486+
tries += 1;
487+
if tries > 8 {
488+
return Err(CoreError::DirRemove(exercise_path.to_path_buf(), err));
489+
}
490+
thread::sleep(Duration::from_secs(1));
491+
}
484492
self.download_or_update_exercises(vec![(exercise_id, exercise_path)])
485493
}
486494

tmc-langs-framework/src/io/tmc_zip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use zip::result::ZipError;
1212
use zip::{write::FileOptions, ZipArchive, ZipWriter};
1313

1414
/// Zips the given directory, only including student files according to the given policy.
15-
pub fn zip(policy: Box<dyn StudentFilePolicy>, root_directory: &Path) -> Result<Vec<u8>> {
15+
pub fn zip<P: StudentFilePolicy>(policy: P, root_directory: &Path) -> Result<Vec<u8>> {
1616
let mut writer = ZipWriter::new(Cursor::new(vec![]));
1717
let tmc_project_yml = policy.get_tmc_project_yml()?;
1818

tmc-langs-framework/src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub trait LanguagePlugin {
149149
/// Compress a given project so that it can be sent to the TestMyCode server.
150150
fn compress_project(&self, path: &Path) -> Result<Vec<u8>> {
151151
let policy = Self::get_student_file_policy(path);
152-
Ok(tmc_zip::zip(Box::new(policy), path)?)
152+
Ok(tmc_zip::zip(policy, path)?)
153153
}
154154

155155
fn get_student_file_policy(project_path: &Path) -> Self::StudentFilePolicy;

0 commit comments

Comments
 (0)