Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: webdav/forget: correctly use application config #1241

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/commands/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ impl Runnable for ForgetCmd {
}

impl ForgetCmd {
/// be careful about self VS RUSTIC_APP.config() usage
simonsan marked this conversation as resolved.
Show resolved Hide resolved
/// only the RUSTIC_APP.config() involves the TOML and ENV merged configurations
simonsan marked this conversation as resolved.
Show resolved Hide resolved
/// see https://github.com/rustic-rs/rustic/issues/1242
simonsan marked this conversation as resolved.
Show resolved Hide resolved
fn inner_run(&self) -> Result<()> {
let config = RUSTIC_APP.config();
let repo = open_repository(&config.repository)?;
Expand Down Expand Up @@ -155,7 +158,7 @@ impl ForgetCmd {
(_, _, true) => {}
}

if self.config.prune {
if config.forget.prune {
let mut prune_opts = self.prune_opts.clone();
prune_opts.opts.ignore_snaps = forget_snaps;
prune_opts.run();
Expand Down
18 changes: 12 additions & 6 deletions src/commands/webdav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,49 @@ impl Runnable for WebDavCmd {
}

impl WebDavCmd {
/// be careful about self VS RUSTIC_APP.config() usage
/// only the RUSTIC_APP.config() involves the TOML and ENV merged configurations
/// see https://github.com/rustic-rs/rustic/issues/1242
fn inner_run(&self) -> Result<()> {
let config = RUSTIC_APP.config();
let repo = open_repository_indexed(&config.repository)?;

let path_template = self
let path_template = config
.webdav
.path_template
.clone()
.unwrap_or_else(|| "[{hostname}]/[{label}]/{time}".to_string());
let time_template = self
let time_template = config
.webdav
.time_template
.clone()
.unwrap_or_else(|| "%Y-%m-%d_%H-%M-%S".to_string());

let sn_filter = |sn: &_| config.snapshot_filter.matches(sn);

let vfs = if let Some(snap) = &self.snapshot_path {
let vfs = if let Some(snap) = &config.webdav.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 self.symlinks {
let (latest, identical) = if config.webdav.symlinks {
(Latest::AsLink, IdenticalSnapshot::AsLink)
} else {
(Latest::AsDir, IdenticalSnapshot::AsDir)
};
Vfs::from_snapshots(snapshots, &path_template, &time_template, latest, identical)?
};

let addr = self
let addr = config
.webdav
.address
.clone()
.unwrap_or_else(|| "localhost:8000".to_string())
.to_socket_addrs()?
.next()
.ok_or_else(|| anyhow!("no address given"))?;

let file_access = self.file_access.as_ref().map_or_else(
let file_access = config.webdav.file_access.as_ref().map_or_else(
|| {
if repo.config().is_hot == Some(true) {
Ok(FilePolicy::Forbidden)
Expand Down
Loading