fix(sync): S-08 — document and refine glob matching in sync engine
This commit is contained in:
@@ -985,3 +985,82 @@ fn test_s07_skip_invalid_windows_filenames_push_and_pull() {
|
||||
}
|
||||
let _ = fs::remove_dir_all(&temp_root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_s08_refined_glob_and_directory_exclusions() {
|
||||
let temp_root =
|
||||
std::env::temp_dir().join(format!("sanctum_s08_test_{}", rand::random::<u64>()));
|
||||
let container_path = temp_root.join("s08.sanctum");
|
||||
let source_dir = temp_root.join("source");
|
||||
let restore_dir = temp_root.join("restore");
|
||||
|
||||
fs::create_dir_all(&source_dir).unwrap();
|
||||
fs::create_dir_all(source_dir.join("build")).unwrap();
|
||||
fs::create_dir_all(source_dir.join("logs")).unwrap();
|
||||
fs::create_dir_all(source_dir.join("node_modules").join("dep")).unwrap();
|
||||
fs::create_dir_all(&restore_dir).unwrap();
|
||||
|
||||
let (db, dek) = create_test_container(&container_path);
|
||||
|
||||
// Dateien anlegen
|
||||
fs::write(source_dir.join("main.rs"), b"fn main() {}").unwrap();
|
||||
fs::write(source_dir.join("temp_1.tmp"), b"junk 1").unwrap();
|
||||
fs::write(source_dir.join("build").join("output.bin"), b"binary").unwrap();
|
||||
fs::write(source_dir.join("build").join("notes.txt"), b"keep notes").unwrap();
|
||||
fs::write(source_dir.join("logs").join("sync.log"), b"log data").unwrap();
|
||||
fs::write(
|
||||
source_dir.join("node_modules").join("dep").join("lib.js"),
|
||||
b"module code",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut opts = SyncOptions::default();
|
||||
opts.direction = SyncDirection::Push;
|
||||
opts.quiet = true;
|
||||
opts.exclude_patterns = vec![
|
||||
"*.tmp".to_string(),
|
||||
"build/*.bin".to_string(),
|
||||
"logs/".to_string(),
|
||||
"node_modules".to_string(),
|
||||
];
|
||||
|
||||
// 1. Push
|
||||
let push_stats = run_sync(
|
||||
&db,
|
||||
0,
|
||||
&dek,
|
||||
FORMAT_VERSION,
|
||||
source_dir.to_str().unwrap(),
|
||||
"/",
|
||||
&opts,
|
||||
)
|
||||
.expect("Push sync with refined glob exclusions");
|
||||
|
||||
// Übertragen werden dürfen nur: main.rs und build/notes.txt (2 Dateien)
|
||||
// Ausgeschlossen: temp_1.tmp (*.tmp), build/output.bin (build/*.bin), logs/sync.log (logs/), node_modules/dep/lib.js (node_modules)
|
||||
assert_eq!(push_stats.files_transferred, 2);
|
||||
|
||||
// 2. Pull
|
||||
opts.direction = SyncDirection::Pull;
|
||||
let pull_stats = run_sync(
|
||||
&db,
|
||||
0,
|
||||
&dek,
|
||||
FORMAT_VERSION,
|
||||
"/",
|
||||
restore_dir.to_str().unwrap(),
|
||||
&opts,
|
||||
)
|
||||
.expect("Pull sync with refined glob exclusions");
|
||||
|
||||
assert_eq!(pull_stats.files_transferred, 2);
|
||||
assert!(restore_dir.join("main.rs").exists());
|
||||
assert!(restore_dir.join("build").join("notes.txt").exists());
|
||||
assert!(!restore_dir.join("temp_1.tmp").exists());
|
||||
assert!(!restore_dir.join("build").join("output.bin").exists());
|
||||
assert!(!restore_dir.join("logs").join("sync.log").exists());
|
||||
assert!(!restore_dir.join("node_modules").exists());
|
||||
|
||||
let _ = fs::remove_dir_all(&temp_root);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user