@@ -9,6 +9,7 @@ use std::{
99use tmc_langs_util:: { deserialize, file_util, FileError } ;
1010use walkdir:: WalkDir ;
1111
12+ /// A project directory is a directory which contains directories of courses (which contain a `course_config.toml`).
1213#[ derive( Debug ) ]
1314pub struct ProjectsConfig {
1415 // BTreeMap used so the exercises in the config file are ordered by key
@@ -19,26 +20,39 @@ impl ProjectsConfig {
1920 pub fn load ( projects_dir : & Path ) -> Result < ProjectsConfig , LangsError > {
2021 file_util:: lock!( projects_dir) ;
2122 let mut course_configs = HashMap :: new ( ) ;
22- for file in WalkDir :: new ( projects_dir) . min_depth ( 1 ) . max_depth ( 1 ) {
23- let file = file?;
24- let course_config_path = file. path ( ) . join ( "course_config.toml" ) ;
23+
24+ let mut unexpected_entries = Vec :: new ( ) ;
25+ for entry in WalkDir :: new ( projects_dir) . min_depth ( 1 ) . max_depth ( 1 ) {
26+ let entry = entry?;
27+ let course_config_path = entry. path ( ) . join ( "course_config.toml" ) ;
2528 if course_config_path. exists ( ) {
26- let file_name = file . file_name ( ) ;
29+ let file_name = entry . file_name ( ) ;
2730 let course_dir_name = file_name. to_str ( ) . ok_or_else ( || {
28- LangsError :: FileError ( FileError :: NoFileName ( file . path ( ) . to_path_buf ( ) ) )
31+ LangsError :: FileError ( FileError :: NoFileName ( entry . path ( ) . to_path_buf ( ) ) )
2932 } ) ?;
3033 let file = file_util:: read_file_to_string ( & course_config_path) ?;
3134 let course_config: CourseConfig = deserialize:: toml_from_str ( & file) ?;
3235
3336 course_configs. insert ( course_dir_name. to_string ( ) , course_config) ;
3437 } else {
35- log:: warn!(
36- "File or directory {} with no config file found while loading projects from {}" ,
37- file. path( ) . display( ) ,
38- projects_dir. display( )
39- ) ;
38+ unexpected_entries. push ( entry) ;
4039 }
4140 }
41+
42+ // no need to warn if the directory has no valid course directories at all
43+ if !course_configs. is_empty ( ) {
44+ log:: warn!(
45+ "Files or directories with no config files found \
46+ while loading projects from {}: [{}]",
47+ projects_dir. display( ) ,
48+ unexpected_entries
49+ . iter( )
50+ . filter_map( |ue| ue. path( ) . as_os_str( ) . to_str( ) )
51+ . collect:: <Vec <_>>( )
52+ . join( ", " ) ,
53+ ) ;
54+ }
55+
4256 // maintenance: check that the exercises in the config actually exist on disk
4357 // if any are found that do not, update the course config file accordingly
4458 for ( _, course_config) in course_configs. iter_mut ( ) {
0 commit comments