diff --git a/src/commands/webdav.rs b/src/commands/webdav.rs index e7bc8bf2..a6b7536d 100644 --- a/src/commands/webdav.rs +++ b/src/commands/webdav.rs @@ -58,7 +58,7 @@ impl Override for WebDavCmd { impl Runnable for WebDavCmd { fn run(&self) { - if let Err(err) = self.inner_run() { + if let Err(err) = Self::inner_run(&RUSTIC_APP.config()) { status_err!("{}", err); RUSTIC_APP.shutdown(Shutdown::Crash); }; @@ -66,29 +66,30 @@ impl Runnable for WebDavCmd { } impl WebDavCmd { - fn inner_run(&self) -> Result<()> { - let config = RUSTIC_APP.config(); - let repo = open_repository_indexed(&config.repository)?; - - let path_template = config - .webdav + /// inner_run is implemented as an associated function because the [WebDavCmd] structure + /// might not include the configuration read from the configuration files + /// (or from the environment variables) + fn inner_run(app_config: &RusticConfig) -> Result<()> { + let webdav_config = &app_config.webdav; + let repo = open_repository_indexed(&app_config.repository)?; + + let path_template = webdav_config .path_template .clone() .unwrap_or_else(|| "[{hostname}]/[{label}]/{time}".to_string()); - let time_template = config - .webdav + let time_template = webdav_config .time_template .clone() .unwrap_or_else(|| "%Y-%m-%d_%H-%M-%S".to_string()); - let sn_filter = |sn: &_| config.snapshot_filter.matches(sn); + let sn_filter = |sn: &_| app_config.snapshot_filter.matches(sn); - let vfs = if let Some(snap) = &config.webdav.snapshot_path { + let vfs = if let Some(snap) = &webdav_config.snapshot_path { let node = repo.node_from_snapshot_path(snap, sn_filter)?; Vfs::from_dir_node(&node) } else { let snapshots = repo.get_matching_snapshots(sn_filter)?; - let (latest, identical) = if config.webdav.symlinks { + let (latest, identical) = if webdav_config.symlinks { (Latest::AsLink, IdenticalSnapshot::AsLink) } else { (Latest::AsDir, IdenticalSnapshot::AsDir) @@ -96,8 +97,7 @@ impl WebDavCmd { Vfs::from_snapshots(snapshots, &path_template, &time_template, latest, identical)? }; - let addr = config - .webdav + let addr = webdav_config .address .clone() .unwrap_or_else(|| "localhost:8000".to_string()) @@ -105,7 +105,7 @@ impl WebDavCmd { .next() .ok_or_else(|| anyhow!("no address given"))?; - let file_access = config.webdav.file_access.as_ref().map_or_else( + let file_access = webdav_config.file_access.as_ref().map_or_else( || { if repo.config().is_hot == Some(true) { Ok(FilePolicy::Forbidden)