@@ -118,21 +118,17 @@ where
118118 }
119119 None => Default :: default ( ) ,
120120 } ;
121- let toml_resolver = TomlResolver :: new (
122- & toml,
123- local_app_dir,
124- provided_state_dir,
125- provided_log_dir,
126- refresh_logs,
127- ) ;
121+ let toml_resolver =
122+ TomlResolver :: new ( & toml, local_app_dir, provided_state_dir, provided_log_dir) ;
128123
129- Self :: new ( toml_resolver, runtime_config_path)
124+ Self :: new ( toml_resolver, runtime_config_path, refresh_logs )
130125 }
131126
132127 /// Creates a new resolved runtime configuration from a TOML table.
133128 pub fn new (
134129 toml_resolver : TomlResolver < ' _ > ,
135130 runtime_config_path : Option < & Path > ,
131+ refresh_logs : bool ,
136132 ) -> anyhow:: Result < Self > {
137133 let runtime_config_dir = runtime_config_path
138134 . and_then ( Path :: parent)
@@ -147,6 +143,11 @@ where
147143
148144 let toml = toml_resolver. toml ( ) ;
149145 let log_dir = toml_resolver. log_dir ( ) ?;
146+
147+ if refresh_logs {
148+ let _ = Self :: resolve_log_dir ( & log_dir) ;
149+ }
150+
150151 let max_instance_memory = toml_resolver. max_instance_memory ( ) ?;
151152
152153 let source = TomlRuntimeConfigSource :: new (
@@ -172,6 +173,14 @@ where
172173 } )
173174 }
174175
176+ fn resolve_log_dir ( log_dir : & Option < PathBuf > ) -> std:: io:: Result < ( ) > {
177+ if let Some ( path) = log_dir {
178+ std:: fs:: remove_dir_all ( path)
179+ } else {
180+ Ok ( ( ) )
181+ }
182+ }
183+
175184 /// The fully resolved state directory.
176185 pub fn state_dir ( & self ) -> Option < PathBuf > {
177186 self . state_dir . clone ( )
@@ -198,8 +207,6 @@ pub struct TomlResolver<'a> {
198207 state_dir : UserProvidedPath ,
199208 /// Explicitly provided log directory.
200209 log_dir : UserProvidedPath ,
201- /// Whether to refresh logs when restarted.
202- refresh_logs : bool ,
203210}
204211
205212impl < ' a > TomlResolver < ' a > {
@@ -209,14 +216,12 @@ impl<'a> TomlResolver<'a> {
209216 local_app_dir : Option < PathBuf > ,
210217 state_dir : UserProvidedPath ,
211218 log_dir : UserProvidedPath ,
212- refresh_logs : bool ,
213219 ) -> Self {
214220 Self {
215221 table : TomlKeyTracker :: new ( table) ,
216222 local_app_dir,
217223 state_dir,
218224 log_dir,
219- refresh_logs,
220225 }
221226 }
222227
@@ -278,17 +283,7 @@ impl<'a> TomlResolver<'a> {
278283 }
279284
280285 match log_dir {
281- UserProvidedPath :: Provided ( p) if self . refresh_logs => Ok ( Some ( {
282- let _ = std:: fs:: remove_dir_all ( & p) ;
283-
284- std:: path:: absolute ( p) ?
285- } ) ) ,
286286 UserProvidedPath :: Provided ( p) => Ok ( Some ( std:: path:: absolute ( p) ?) ) ,
287- UserProvidedPath :: Default if self . refresh_logs => Ok ( self . state_dir ( ) ?. map ( |p| {
288- let _ = std:: fs:: remove_dir_all ( & p) ;
289-
290- p. join ( "logs" )
291- } ) ) ,
292287 UserProvidedPath :: Default => Ok ( self . state_dir ( ) ?. map ( |p| p. join ( "logs" ) ) ) ,
293288 UserProvidedPath :: Unset => Ok ( None ) ,
294289 }
@@ -513,6 +508,7 @@ mod tests {
513508 ResolvedRuntimeConfig :: <TestFactorsRuntimeConfig >:: new(
514509 toml_resolver( & toml) ,
515510 Some ( path. as_ref( ) ) ,
511+ false ,
516512 )
517513 }
518514 } ;
@@ -639,7 +635,6 @@ mod tests {
639635 None ,
640636 UserProvidedPath :: Default ,
641637 UserProvidedPath :: Default ,
642- false ,
643638 )
644639 }
645640
0 commit comments