@@ -41,6 +41,8 @@ pub struct LogDirectoryConfig {
4141 #[ serde( default = "default_directory_include" ) ]
4242 pub include : Vec < String > ,
4343 #[ serde( default ) ]
44+ pub exclude : Vec < String > ,
45+ #[ serde( default ) ]
4446 pub recursive : bool ,
4547}
4648
@@ -81,6 +83,7 @@ impl AppConfig {
8183 }
8284
8385 for directory in & mut cfg. directories {
86+ validate_directory_path ( & directory. path ) ?;
8487 if directory. path . is_relative ( ) {
8588 directory. path = base. join ( & directory. path ) ;
8689 }
@@ -91,6 +94,17 @@ impl AppConfig {
9194 }
9295}
9396
97+ fn validate_directory_path ( path : & Path ) -> anyhow:: Result < ( ) > {
98+ let source = path. to_string_lossy ( ) ;
99+ if source. contains ( '*' ) || source. contains ( '?' ) || source. contains ( '[' ) {
100+ anyhow:: bail!(
101+ "directories.path must be a real directory, put patterns in include instead: path = {:?}" ,
102+ path
103+ ) ;
104+ }
105+ Ok ( ( ) )
106+ }
107+
94108fn absolutize ( path : & Path ) -> anyhow:: Result < PathBuf > {
95109 if path. exists ( ) {
96110 return Ok ( path. canonicalize ( ) ?) ;
@@ -153,6 +167,28 @@ path = "./logs"
153167 config. directories[ 0 ] . include,
154168 vec![ "*.log" , "*.gz" , "*.zst" , "*.bz2" , "*.xz" ]
155169 ) ;
170+ assert ! ( config. directories[ 0 ] . exclude. is_empty( ) ) ;
156171 assert ! ( !config. directories[ 0 ] . recursive) ;
157172 }
173+
174+ #[ test]
175+ fn rejects_glob_patterns_in_directory_path ( ) {
176+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
177+ let config_path = dir. path ( ) . join ( "config.toml" ) ;
178+ std:: fs:: write (
179+ & config_path,
180+ r#"
181+ [[directories]]
182+ id = "release"
183+ path = "./logs/**"
184+ include = ["*.log"]
185+ "# ,
186+ )
187+ . unwrap ( ) ;
188+
189+ let err = AppConfig :: load ( & config_path) . unwrap_err ( ) ;
190+
191+ assert ! ( err. to_string( ) . contains( "directories.path must be a real directory" ) ) ;
192+ assert ! ( err. to_string( ) . contains( "put patterns in include instead" ) ) ;
193+ }
158194}
0 commit comments