Skip to content

Commit aff1e5e

Browse files
authored
Merge pull request #579 from rustic-rs/fix-changed-dir
backup: only show changed dirs if there are changes
2 parents 9f08070 + 5b2ae17 commit aff1e5e

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

changelog/new.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bugs fixed:
1111
- restore: Setting ownership/permissons/times for symlinks failed. This has been fixed.
1212
- Spaces in paths did not work when given in the config file. This has been fixed.
1313
- backup --stdin-filename did not use the given filename. This has been fixed.
14+
- backup always displayed at least 1 dir as changed. This has been corrected.
1415

1516
New features:
1617
- REST backend: Set User-Agent header

src/archiver/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ use log::*;
1717

1818
use crate::backend::{DecryptWriteBackend, ReadSource, ReadSourceEntry};
1919
use crate::blob::BlobType;
20+
use crate::id::Id;
2021
use crate::index::{IndexedBackend, Indexer, SharedIndexer};
2122
use crate::repofile::{ConfigFile, SnapshotFile};
2223

2324
pub struct Archiver<BE: DecryptWriteBackend, I: IndexedBackend> {
2425
file_archiver: FileArchiver<BE, I>,
2526
tree_archiver: TreeArchiver<BE, I>,
27+
parent_tree: Option<Id>,
2628
parent: Parent<I>,
2729
indexer: SharedIndexer<BE>,
2830
be: BE,
@@ -34,18 +36,22 @@ impl<BE: DecryptWriteBackend, I: IndexedBackend> Archiver<BE, I> {
3436
be: BE,
3537
index: I,
3638
config: &ConfigFile,
37-
parent: Parent<I>,
39+
parent_tree: Option<Id>,
40+
ignore_ctime: bool,
41+
ignore_inode: bool,
3842
mut snap: SnapshotFile,
3943
) -> Result<Self> {
4044
let indexer = Indexer::new(be.clone()).into_shared();
4145
let mut summary = snap.summary.take().unwrap();
4246
summary.backup_start = Local::now();
4347

48+
let parent = Parent::new(&index, parent_tree, ignore_ctime, ignore_inode);
4449
let file_archiver = FileArchiver::new(be.clone(), index.clone(), indexer.clone(), config)?;
4550
let tree_archiver = TreeArchiver::new(be.clone(), index, indexer.clone(), config, summary)?;
4651
Ok(Self {
4752
file_archiver,
4853
tree_archiver,
54+
parent_tree,
4955
parent,
5056
be,
5157
indexer,
@@ -121,14 +127,8 @@ impl<BE: DecryptWriteBackend, I: IndexedBackend> Archiver<BE, I> {
121127
self.tree_archiver.add(item)?;
122128
}
123129

124-
let snap = self.finalize_snapshot()?;
125-
p.finish_with_message("done");
126-
Ok(snap)
127-
}
128-
129-
pub fn finalize_snapshot(mut self) -> Result<SnapshotFile> {
130130
let stats = self.file_archiver.finalize()?;
131-
let (id, mut summary) = self.tree_archiver.finalize()?;
131+
let (id, mut summary) = self.tree_archiver.finalize(self.parent_tree)?;
132132
stats.apply(&mut summary, BlobType::Data);
133133
self.snap.tree = id;
134134

@@ -140,6 +140,7 @@ impl<BE: DecryptWriteBackend, I: IndexedBackend> Archiver<BE, I> {
140140
let id = self.be.save_file(&self.snap)?;
141141
self.snap.id = id;
142142

143+
p.finish_with_message("done");
143144
Ok(self.snap)
144145
}
145146
}

src/archiver/tree_archiver.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ impl<BE: DecryptWriteBackend, I: IndexedBackend> TreeArchiver<BE, I> {
127127
Ok(id)
128128
}
129129

130-
pub fn finalize(mut self) -> Result<(Id, SnapshotSummary)> {
131-
let id = self.backup_tree(&PathBuf::new(), ParentResult::NotMatched)?;
130+
pub fn finalize(mut self, parent_tree: Option<Id>) -> Result<(Id, SnapshotSummary)> {
131+
let parent = match parent_tree {
132+
None => ParentResult::NotMatched,
133+
Some(id) => ParentResult::Matched(id),
134+
};
135+
let id = self.backup_tree(&PathBuf::new(), parent)?;
132136
let stats = self.tree_packer.finalize()?;
133137
stats.apply(&mut self.summary, BlobType::Tree);
134138

src/commands/backup.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::Deserialize;
1111
use toml::Value;
1212

1313
use super::{bytes, progress_bytes, progress_counter, RusticConfig};
14-
use crate::archiver::{Archiver, Parent};
14+
use crate::archiver::Archiver;
1515
use crate::backend::{DryRunBackend, LocalSource, LocalSourceOptions, StdinSource};
1616
use crate::index::IndexBackend;
1717
use crate::repofile::{
@@ -206,9 +206,15 @@ pub(super) fn execute(
206206
}
207207
};
208208

209-
let parent = Parent::new(&index, parent_tree, opts.ignore_ctime, opts.ignore_inode);
210-
211-
let archiver = Archiver::new(be, index, &repo.config, parent, snap)?;
209+
let archiver = Archiver::new(
210+
be,
211+
index,
212+
&repo.config,
213+
parent_tree,
214+
opts.ignore_ctime,
215+
opts.ignore_inode,
216+
snap,
217+
)?;
212218
let p = progress_bytes("determining size...");
213219

214220
let snap = if backup_stdin {

0 commit comments

Comments
 (0)