Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion crates/core/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ impl<'a, BE: DecryptFullBackend, I: ReadGlobalIndex> Archiver<'a, BE, I> {
} else {
path
};
Some(if node.is_dir() {
// A directory given with its subtree is kept as it is, like a file:
// its tree is already in the repository and is not built again.
Some(if node.is_dir() && node.subtree.is_none() {
(snapshot_path, node, open)
} else {
(
Expand Down
7 changes: 7 additions & 0 deletions crates/core/src/archiver/tree_archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> TreeArchiver<'a, BE, I> {
/// * `parent` - The parent result of the file.
fn add_file(&mut self, path: &Path, node: Node, parent: &ParentResult<()>, size: u64) {
let filename = path.join(node.name());
if node.is_dir() {
debug!("kept tree: {}", filename.display());
self.summary.dirs_unmodified += 1;
self.summary.total_dirs_processed += 1;
self.tree.add(node);
return;
}
match parent {
ParentResult::Matched(()) => {
debug!("unchanged file: {}", filename.display());
Expand Down
69 changes: 67 additions & 2 deletions crates/core/tests/integration/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use pretty_assertions::assert_eq;
use rstest::rstest;

use rustic_core::{
BackupOptions, CommandInput, Grouped, ParentOptions, PathList, SnapshotGroupCriterion,
SnapshotOptions, StringList,
BackupOptions, CommandInput, Grouped, ParentOptions, PathList, ReadSource, ReadSourceEntry,
ReadSourceOpen, RusticResult, SnapshotGroupCriterion, SnapshotOptions, StringList,
repofile::{PackId, SnapshotFile},
};

Expand Down Expand Up @@ -349,3 +349,68 @@ fn test_backup_unreadable_file_sets_error_count(set_up_repo: Result<RepoOpen>) -

Ok(())
}

/// Opens nothing: every entry of [`GivenEntries`] is stored as given.
#[derive(Clone, Copy)]
struct NothingToRead;

impl ReadSourceOpen for NothingToRead {
type Reader = std::io::Empty;

fn open(self) -> RusticResult<Self::Reader> {
Ok(std::io::empty())
}
}

/// A source of ready-made entries.
struct GivenEntries(Vec<ReadSourceEntry<NothingToRead>>);

impl ReadSource for GivenEntries {
type Open = NothingToRead;
type Iter = std::iter::Map<
std::vec::IntoIter<ReadSourceEntry<NothingToRead>>,
fn(ReadSourceEntry<NothingToRead>) -> RusticResult<ReadSourceEntry<NothingToRead>>,
>;

fn size(&self) -> RusticResult<Option<u64>> {
Ok(None)
}

fn entries(&self) -> Self::Iter {
self.0.clone().into_iter().map(Ok)
}
}

#[rstest]
fn test_archive_keeps_a_directory_given_with_its_subtree(
tar_gz_testdata: Result<TestSource>,
set_up_repo: Result<RepoOpen>,
) -> Result<()> {
let (source, repo) = (tar_gz_testdata?, set_up_repo?.to_indexed_ids()?);
let opts = BackupOptions::default().as_path(PathBuf::from_str("test")?);
let first = repo.backup(&opts, &source.path_list(), SnapshotFile::default())?;
let repo = repo.to_indexed_ids()?;
let stored = repo.node_from_path(first.tree, Path::new("test/0/tests"))?;
let subtree = stored.subtree.expect("a directory has a subtree");

// A source giving that directory, subtree and all, and nothing below it.
let mut kept = stored;
kept.name = "kept".to_string();
let given = GivenEntries(vec![ReadSourceEntry {
path: PathBuf::from("kept"),
node: kept,
open: None,
}]);
let second = repo.archive(
&BackupOptions::default(),
&given,
SnapshotFile::default(),
&[PathBuf::from("kept")],
)?;

let repo = repo.to_indexed_ids()?;
let archived = repo.node_from_path(second.tree, Path::new("kept"))?;
assert_eq!(archived.subtree, Some(subtree));
assert_eq!(second.summary.expect("a summary").dirs_unmodified, 1);
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
source: crates/core/tests/integration/chunker.rs
assertion_line: 44
expression: "&snapshot"
---
SnapshotFile(
time: "[time]",
program_version: "rustic [rustic_core_version]",
tree: "[tree_id]",
paths: StringList([
"test",
]),
hostname: "[hostname]",
username: "",
uid: 0,
gid: 0,
tags: StringList([]),
summary: Some(SnapshotSummary(
files_new: 73,
files_changed: 0,
files_unmodified: 0,
total_files_processed: 73,
total_bytes_processed: 1125674,
dirs_new: 6,
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 6,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 207,
tree_blobs: 6,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 1125653,
data_added_files_packed: 181652,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "[command]",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
backup_duration: "[backup_duration]",
total_duration: "[total_duration]",
)),
id: "[id]",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
source: crates/core/tests/integration.rs
assertion_line: 199
expression: snap
---
SnapshotFile(
time: "[time]",
program_version: "rustic [rustic_core_version]",
tree: "[tree_id]",
paths: StringList([
"test",
]),
hostname: "[hostname]",
username: "",
uid: 0,
gid: 0,
tags: StringList([]),
summary: Some(SnapshotSummary(
files_new: 73,
files_changed: 0,
files_unmodified: 0,
total_files_processed: 73,
total_bytes_processed: 1125674,
dirs_new: 6,
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 6,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 70,
tree_blobs: 6,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 1125653,
data_added_files_packed: 78740,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "[command]",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
backup_duration: "[backup_duration]",
total_duration: "[total_duration]",
)),
id: "[id]",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/core/tests/integration.rs
assertion_line: 199
expression: snap
---
SnapshotFile(
time: "[time]",
program_version: "rustic [rustic_core_version]",
tree: "[tree_id]",
paths: StringList([
"test",
]),
hostname: "[hostname]",
username: "",
uid: 0,
gid: 0,
tags: StringList([]),
summary: Some(SnapshotSummary(
files_new: 73,
files_changed: 0,
files_unmodified: 0,
total_files_processed: 73,
total_bytes_processed: 1125674,
dirs_new: 6,
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 6,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 70,
tree_blobs: 6,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 1125653,
data_added_files_packed: 78740,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "[command]",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
backup_duration: "[backup_duration]",
total_duration: "[total_duration]",
)),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: crates/core/tests/integration.rs
assertion_line: 199
expression: snap
---
[
SnapshotFile(
time: "[time]",
program_version: "rustic [rustic_core_version]",
tree: "[tree_id]",
label: "label",
paths: StringList([
"test",
]),
hostname: "[hostname]",
username: "",
uid: 0,
gid: 0,
tags: StringList([
"tag1",
"tag2",
]),
delete: Never,
summary: Some(SnapshotSummary(
files_new: 73,
files_changed: 0,
files_unmodified: 0,
total_files_processed: 73,
total_bytes_processed: 1125674,
dirs_new: 6,
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 6,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 70,
tree_blobs: 6,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 1125653,
data_added_files_packed: 78740,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "[command]",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
backup_duration: "[backup_duration]",
total_duration: "[total_duration]",
)),
description: Some("description"),
id: "[id]",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
source: crates/core/tests/integration.rs
assertion_line: 199
expression: snap
---
SnapshotFile(
time: "[time]",
program_version: "rustic [rustic_core_version]",
tree: "[tree_id]",
paths: StringList([
"test",
]),
hostname: "[hostname]",
username: "",
uid: 0,
gid: 0,
tags: StringList([]),
summary: Some(SnapshotSummary(
files_new: 1,
files_changed: 0,
files_unmodified: 0,
total_files_processed: 1,
total_bytes_processed: 5,
dirs_new: 1,
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 1,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 1,
tree_blobs: 1,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 5,
data_added_files_packed: 46,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "[command]",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
backup_duration: "[backup_duration]",
total_duration: "[total_duration]",
)),
id: "[id]",
)