Skip to content
Open
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
34 changes: 32 additions & 2 deletions crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl LocalSource {
///
/// # Errors
///
/// * If `backup_paths` is empty.
/// * If the a glob pattern could not be added to the override builder.
/// * If a glob file could not be read.
#[allow(clippy::too_many_lines)]
Expand All @@ -133,9 +134,16 @@ impl LocalSource {
filter_opts: &LocalSourceFilterOptions,
backup_paths: &[impl AsRef<Path>],
) -> RusticResult<Self> {
let mut walk_builder = WalkBuilder::new(&backup_paths[0]);
let (first, rest) = backup_paths.split_first().ok_or_else(|| {
RusticError::new(
ErrorKind::InvalidInput,
"Cannot create local source: backup_paths cannot be empty.",
)
})?;

let mut walk_builder = WalkBuilder::new(first);

for path in &backup_paths[1..] {
for path in rest {
_ = walk_builder.add(path);
}

Expand Down Expand Up @@ -347,3 +355,25 @@ impl Iterator for LocalSourceWalker {
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_local_source_new_empty_backup_paths() {
let save_opts = LocalSourceSaveOptions::default();
let excludes = Excludes::default();
let filter_opts = LocalSourceFilterOptions::default();
let empty_paths: &[&Path] = &[];

let result = LocalSource::new(save_opts, &excludes, &filter_opts, empty_paths);
assert!(result.is_err());
assert!(
result
.unwrap_err()
.to_string()
.contains("backup_paths cannot be empty")
);
}
}