Skip to content

Commit 9d09742

Browse files
committed
refactor: renaming + login
Signed-off-by: Aminu 'Seun Joshua <[email protected]>
1 parent 0a252ba commit 9d09742

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

crates/runtime-config/src/lib.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

205212
impl<'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

crates/trigger/src/cli.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use stdio::StdioLoggingExecutorHooks;
2727
pub use summary::{KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook};
2828

2929
pub const APP_LOG_DIR: &str = "APP_LOG_DIR";
30-
pub const REFRESH_LOGS: &str = "REFRESH_LOGS";
30+
pub const SPIN_REFRESH_LOGS: &str = "SPIN_REFRESH_LOGS";
3131
pub const DISABLE_WASMTIME_CACHE: &str = "DISABLE_WASMTIME_CACHE";
3232
pub const FOLLOW_LOG_OPT: &str = "FOLLOW_ID";
3333
pub const WASMTIME_CACHE_FILE: &str = "WASMTIME_CACHE_FILE";
@@ -55,10 +55,9 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
5555
)]
5656
pub log: Option<PathBuf>,
5757

58-
/// Whether to refresh logs when restarted.
58+
/// If set, Spin deletes the log files before starting the application.
5959
#[clap(
60-
name = REFRESH_LOGS,
61-
short = 'r',
60+
name = SPIN_REFRESH_LOGS,
6261
long = "refresh-logs",
6362
)]
6463
pub refresh_logs: bool,

0 commit comments

Comments
 (0)