Skip to content

Commit f6ae324

Browse files
committed
fix .tmcproject.yml files getting filtered in course refresh
1 parent 28ae714 commit f6ae324

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tmc-langs/src/course_refresher.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,20 @@ fn execute_zip(
387387
let zip_file_path = zip_dir.join(format!("{}.zip", exercise.name));
388388

389389
let mut writer = zip::ZipWriter::new(file_util::create_file(zip_file_path)?);
390+
391+
// hidden files are filtered, so we handle .tmcproject.yml here
392+
let tmcproject_yml_path = exercise_root.join(".tmcproject.yml");
393+
if tmcproject_yml_path.exists() {
394+
let tmcproject_yml = file_util::read_file(&tmcproject_yml_path)?;
395+
let relative_path = tmcproject_yml_path.strip_prefix(&root_path).unwrap(); // safe
396+
writer.start_file(
397+
relative_path.to_string_lossy(),
398+
zip::write::FileOptions::default(),
399+
)?;
400+
writer
401+
.write_all(&tmcproject_yml)
402+
.map_err(LangsError::ZipWrite)?;
403+
}
390404
for entry in WalkDir::new(&exercise_root).into_iter().filter_entry(|e| {
391405
!e.file_name()
392406
.to_str()
@@ -570,12 +584,14 @@ mod test {
570584
file_to(&temp, "clone/part2/ex2/setup.py", "");
571585
file_to(&temp, "clone/part2/ex2/dir/subdir/file", "");
572586
file_to(&temp, "clone/part2/ex2/dir/subdir/.hidden", "");
587+
file_to(&temp, "clone/part2/ex2/.tmcproject.yml", "some: 'yaml'");
573588
file_to(&temp, "stub/part1/ex1/setup.py", "");
574589
file_to(&temp, "stub/part1/ex2/setup.py", "");
575590
file_to(&temp, "stub/part2/ex1/setup.py", "");
576591
file_to(&temp, "stub/part2/ex2/setup.py", "");
577592
file_to(&temp, "stub/part2/ex2/dir/subdir/file", "some file");
578593
file_to(&temp, "stub/part2/ex2/dir/subdir/.hidden", "hidden file");
594+
file_to(&temp, "stub/part2/ex2/.tmcproject.yml", "some: 'yaml'");
579595

580596
let exercise_dirs = find_exercise_directories(&temp.path().join("clone"))
581597
.unwrap()
@@ -643,7 +659,20 @@ mod test {
643659
.unwrap(); // other files have their stub contents
644660
let mut buf = String::new();
645661
file.read_to_string(&mut buf).unwrap();
662+
drop(file);
663+
646664
assert_eq!(buf, "some file");
665+
let mut file = fz
666+
.by_name(
667+
&Path::new("part2")
668+
.join("ex2")
669+
.join(".tmcproject.yml")
670+
.to_string_lossy(),
671+
)
672+
.unwrap(); // .tmcproject.yml is not filtered out
673+
let mut buf = String::new();
674+
file.read_to_string(&mut buf).unwrap();
675+
assert_eq!(buf, "some: 'yaml'");
647676
}
648677

649678
#[test]

0 commit comments

Comments
 (0)