Skip to content

Commit

Permalink
fix .tmcproject.yml files getting filtered in course refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Heliozoa committed Oct 14, 2021
1 parent 5ba3093 commit a6062a7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tmc-langs/src/course_refresher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,20 @@ fn execute_zip(
let zip_file_path = zip_dir.join(format!("{}.zip", exercise.name));

let mut writer = zip::ZipWriter::new(file_util::create_file(zip_file_path)?);

// hidden files are filtered, so we handle .tmcproject.yml here
let tmcproject_yml_path = exercise_root.join(".tmcproject.yml");
if tmcproject_yml_path.exists() {
let tmcproject_yml = file_util::read_file(&tmcproject_yml_path)?;
let relative_path = tmcproject_yml_path.strip_prefix(&root_path).unwrap(); // safe
writer.start_file(
relative_path.to_string_lossy(),
zip::write::FileOptions::default(),
)?;
writer
.write_all(&tmcproject_yml)
.map_err(LangsError::ZipWrite)?;
}
for entry in WalkDir::new(&exercise_root).into_iter().filter_entry(|e| {
!e.file_name()
.to_str()
Expand Down Expand Up @@ -530,12 +544,14 @@ mod test {
file_to(&temp, "clone/part2/ex2/setup.py", "");
file_to(&temp, "clone/part2/ex2/dir/subdir/file", "");
file_to(&temp, "clone/part2/ex2/dir/subdir/.hidden", "");
file_to(&temp, "clone/part2/ex2/.tmcproject.yml", "some: 'yaml'");
file_to(&temp, "stub/part1/ex1/setup.py", "");
file_to(&temp, "stub/part1/ex2/setup.py", "");
file_to(&temp, "stub/part2/ex1/setup.py", "");
file_to(&temp, "stub/part2/ex2/setup.py", "");
file_to(&temp, "stub/part2/ex2/dir/subdir/file", "some file");
file_to(&temp, "stub/part2/ex2/dir/subdir/.hidden", "hidden file");
file_to(&temp, "stub/part2/ex2/.tmcproject.yml", "some: 'yaml'");

let exercise_dirs = find_exercise_directories(&temp.path().join("clone"))
.unwrap()
Expand Down Expand Up @@ -603,7 +619,20 @@ mod test {
.unwrap(); // other files have their stub contents
let mut buf = String::new();
file.read_to_string(&mut buf).unwrap();
drop(file);

assert_eq!(buf, "some file");
let mut file = fz
.by_name(
&Path::new("part2")
.join("ex2")
.join(".tmcproject.yml")
.to_string_lossy(),
)
.unwrap(); // .tmcproject.yml is not filtered out
let mut buf = String::new();
file.read_to_string(&mut buf).unwrap();
assert_eq!(buf, "some: 'yaml'");
}

#[test]
Expand Down

0 comments on commit a6062a7

Please sign in to comment.