11//! Student file policy for C#
22
3- use std:: ffi:: OsString ;
43use std:: path:: { Path , PathBuf } ;
54use tmc_langs_framework:: StudentFilePolicy ;
65
@@ -17,16 +16,12 @@ impl CSharpStudentFilePolicy {
1716
1817 /// Goes up directories until a bin or obj directory is found
1918 fn is_child_of_binary_dir ( & self , path : & Path ) -> bool {
20- let mut parent = path. parent ( ) ;
21- while let Some ( next) = parent {
22- if let Some ( file_name) = next. file_name ( ) {
23- if next. is_dir ( )
24- && ( file_name == OsString :: from ( "bin" ) || file_name == OsString :: from ( "obj" ) )
25- {
19+ for ancestor in path. ancestors ( ) {
20+ if let Some ( file_name) = ancestor. file_name ( ) {
21+ if ancestor. is_dir ( ) && ( file_name == "bin" || file_name == "obj" ) {
2622 return true ;
2723 }
2824 }
29- parent = next. parent ( ) ;
3025 }
3126 false
3227 }
@@ -35,11 +30,7 @@ impl CSharpStudentFilePolicy {
3530impl StudentFilePolicy for CSharpStudentFilePolicy {
3631 // false for files in bin or obj directories, true for other files in src
3732 fn is_student_source_file ( & self , path : & Path ) -> bool {
38- if self . is_child_of_binary_dir ( path) {
39- false
40- } else {
41- path. starts_with ( "src" )
42- }
33+ path. starts_with ( "src" ) && !self . is_child_of_binary_dir ( path)
4334 }
4435
4536 fn get_config_file_parent_path ( & self ) -> & Path {
0 commit comments