Skip to content

Commit

Permalink
refactor: webdav inner_run cmd to an associated function
Browse files Browse the repository at this point in the history
  • Loading branch information
nardoor committed Sep 17, 2024
1 parent 6134e93 commit 296cc14
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/commands/webdav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,54 +58,54 @@ impl Override<RusticConfig> 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);
};
}
}

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)
};
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())
.to_socket_addrs()?
.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)
Expand Down

0 comments on commit 296cc14

Please sign in to comment.