Skip to content

Commit 1d22688

Browse files
committed
fix hidden file detection
1 parent 37c85b5 commit 1d22688

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

tmc-langs/src/submission_processing.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use tmc_langs_util::file_util;
99
use walkdir::{DirEntry, WalkDir};
1010

1111
lazy_static! {
12-
static ref FILES_TO_SKIP_ALWAYS: Regex =
13-
Regex::new(r"\.tmcrc|^metadata\.yml$|(.*)Hidden(.*)").unwrap();
12+
static ref FILES_TO_SKIP_ALWAYS: Regex = Regex::new(r"\.tmcrc|^metadata\.yml$").unwrap();
1413
static ref NON_TEXT_TYPES: Regex =
1514
Regex::new("class|jar|exe|jpg|jpeg|gif|png|zip|tar|gz|db|bin|csv|tsv|sqlite3|^$").unwrap();
1615
}
@@ -29,13 +28,29 @@ pub fn is_hidden_dir(entry: &DirEntry) -> bool {
2928
skip
3029
}
3130

32-
// Filter for skipping directories on `FILES_TO_SKIP_ALWAYS` or named 'private'
31+
// Filter for skipping directories on `FILES_TO_SKIP_ALWAYS` or named 'private', and files in a 'test' directory that contain 'Hidden' in their name.
3332
fn on_skip_list(entry: &DirEntry) -> bool {
34-
let skip = entry
35-
.file_name()
36-
.to_str()
33+
// check if entry's filename matchees the skip list or is 'private'
34+
let entry_file_name = entry.file_name().to_str();
35+
let on_skip_list = entry_file_name
3736
.map(|s| FILES_TO_SKIP_ALWAYS.is_match(s) || s == "private")
3837
.unwrap_or_default();
38+
39+
// check if the current entry is a file in a "test" directory that contains "Hidden" in its name
40+
let hidden_in_test = if entry.path().is_file() {
41+
if let Some(parent) = entry.path().parent().and_then(|p| p.file_name()) {
42+
parent == "test"
43+
&& entry_file_name
44+
.map(|n| n.contains("Hidden"))
45+
.unwrap_or_default()
46+
} else {
47+
false
48+
}
49+
} else {
50+
false
51+
};
52+
53+
let skip = on_skip_list || hidden_in_test;
3954
if skip {
4055
log::debug!("on skip list: {:?}", entry.path());
4156
}
@@ -388,4 +403,17 @@ extra_student_files:
388403
assert!(conf.extra_student_files[0] == PathBuf::from("test/StudentTest.java"));
389404
assert!(conf.extra_student_files[1] == PathBuf::from("test/OtherTest.java"));
390405
}
406+
407+
#[test]
408+
fn hides_test_hidden_files() {
409+
init();
410+
411+
let temp = tempdir().unwrap();
412+
let temp_path = temp.path();
413+
414+
prepare_solution(Path::new("tests/data/dir"), temp_path).unwrap();
415+
416+
assert!(dbg!(temp_path.join("NotHidden.java")).exists());
417+
assert!(!dbg!(temp_path.join("ActuallyHidden.java")).exists());
418+
}
391419
}

0 commit comments

Comments
 (0)