lcpfs 2026.1.102

LCP File System - A ZFS-inspired copy-on-write filesystem for Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
// Copyright 2025 LunaOS Contributors
// SPDX-License-Identifier: Apache-2.0

//! Delta synchronization operations.
//!
//! This module provides high-level sync operations that use delta
//! compression to efficiently transfer only changed portions of files.

use alloc::string::{String, ToString};
use alloc::vec::Vec;

use super::compute::{
    apply_delta, compute_delta, create_full_insert_delta, file_checksum, generate_signatures,
    optimal_block_size,
};
use super::types::{
    DEFAULT_BLOCK_SIZE, Delta, DeltaError, DeltaResult, MIN_BLOCK_SIZE, SyncEntry, SyncPlan,
    SyncProgress, SyncStatus,
};

// ═══════════════════════════════════════════════════════════════════════════════
// FILE INFO TRAIT
// ═══════════════════════════════════════════════════════════════════════════════

/// Information about a file for sync operations.
#[derive(Debug, Clone)]
pub struct FileInfo {
    /// File path.
    pub path: String,
    /// File size in bytes.
    pub size: u64,
    /// Modification time (nanoseconds since epoch).
    pub mtime: u64,
    /// File checksum.
    pub checksum: [u64; 4],
}

impl FileInfo {
    /// Create a new file info.
    pub fn new(path: &str, size: u64, mtime: u64, checksum: [u64; 4]) -> Self {
        Self {
            path: path.to_string(),
            size,
            mtime,
            checksum,
        }
    }

    /// Check if this file matches another (same content).
    pub fn matches(&self, other: &FileInfo) -> bool {
        self.checksum == other.checksum && self.size == other.size
    }

    /// Check if this file is newer than another.
    pub fn is_newer_than(&self, other: &FileInfo) -> bool {
        self.mtime > other.mtime
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// SYNC OPERATIONS
// ═══════════════════════════════════════════════════════════════════════════════

/// Compare two file lists and create a sync plan.
///
/// # Arguments
/// * `source` - Source directory identifier
/// * `dest` - Destination directory identifier
/// * `source_files` - Files in source
/// * `dest_files` - Files in destination
/// * `timestamp` - Current timestamp
///
/// # Returns
/// SyncPlan describing necessary operations
pub fn plan_sync(
    source: &str,
    dest: &str,
    source_files: &[FileInfo],
    dest_files: &[FileInfo],
    timestamp: u64,
) -> SyncPlan {
    let mut plan = SyncPlan::new(source, dest, timestamp);

    // Build destination lookup
    let dest_lookup: alloc::collections::BTreeMap<&str, &FileInfo> =
        dest_files.iter().map(|f| (f.path.as_str(), f)).collect();

    // Build source lookup for rename detection
    let source_by_checksum: alloc::collections::BTreeMap<[u64; 4], &FileInfo> =
        source_files.iter().map(|f| (f.checksum, f)).collect();

    // Track processed dest files
    let mut processed_dest: alloc::collections::BTreeSet<&str> =
        alloc::collections::BTreeSet::new();

    // Check each source file
    for src_file in source_files {
        if let Some(dest_file) = dest_lookup.get(src_file.path.as_str()) {
            processed_dest.insert(&dest_file.path);

            if src_file.matches(dest_file) {
                // Unchanged
                plan.add_entry(SyncEntry::new(
                    &src_file.path,
                    src_file.size,
                    src_file.mtime,
                    src_file.checksum,
                    SyncStatus::Unchanged,
                ));
            } else {
                // Modified
                plan.add_entry(SyncEntry::new(
                    &src_file.path,
                    src_file.size,
                    src_file.mtime,
                    src_file.checksum,
                    SyncStatus::Modified,
                ));
            }
        } else {
            // Check if it's a rename (same checksum exists in dest with different name)
            let mut is_rename = false;
            for dest_file in dest_files {
                if !processed_dest.contains(dest_file.path.as_str())
                    && dest_file.checksum == src_file.checksum
                    && dest_file.path != src_file.path
                {
                    // This is a rename
                    processed_dest.insert(&dest_file.path);
                    plan.add_entry(
                        SyncEntry::new(
                            &src_file.path,
                            src_file.size,
                            src_file.mtime,
                            src_file.checksum,
                            SyncStatus::Renamed,
                        )
                        .with_original(&dest_file.path),
                    );
                    is_rename = true;
                    break;
                }
            }

            if !is_rename {
                // New file
                plan.add_entry(SyncEntry::new(
                    &src_file.path,
                    src_file.size,
                    src_file.mtime,
                    src_file.checksum,
                    SyncStatus::New,
                ));
            }
        }
    }

    // Files in dest but not in source are deleted
    for dest_file in dest_files {
        if !processed_dest.contains(dest_file.path.as_str()) {
            plan.add_entry(SyncEntry::new(
                &dest_file.path,
                dest_file.size,
                dest_file.mtime,
                dest_file.checksum,
                SyncStatus::Deleted,
            ));
        }
    }

    plan
}

/// Compute delta for a modified file.
///
/// # Arguments
/// * `old_data` - Existing file data (in destination)
/// * `new_data` - New file data (from source)
///
/// # Returns
/// Delta to transform old_data into new_data
pub fn compute_file_delta(old_data: &[u8], new_data: &[u8]) -> DeltaResult<Delta> {
    let block_size = optimal_block_size(old_data.len() as u64).max(MIN_BLOCK_SIZE);
    let sigs = generate_signatures(old_data, block_size)?;
    compute_delta(&sigs, new_data)
}

/// Compute delta for a new file (no existing version).
///
/// # Arguments
/// * `data` - New file data
///
/// # Returns
/// Delta containing full file insert
pub fn compute_new_file_delta(data: &[u8]) -> Delta {
    create_full_insert_delta(data)
}

/// Apply a delta to reconstruct file content.
///
/// # Arguments
/// * `old_data` - Existing file data
/// * `delta` - Delta to apply
///
/// # Returns
/// Reconstructed new file data
pub fn apply_file_delta(old_data: &[u8], delta: &Delta) -> DeltaResult<Vec<u8>> {
    apply_delta(old_data, delta)
}

/// Estimate transfer size for a sync plan without computing full deltas.
///
/// Uses heuristics based on file sizes and modification status.
pub fn estimate_transfer_size(plan: &SyncPlan) -> u64 {
    plan.entries
        .iter()
        .map(|e| match e.status {
            SyncStatus::New => e.size,
            SyncStatus::Modified => {
                // Estimate 20% change ratio for modified files
                (e.size as f64 * 0.2) as u64 + 1024 // Plus overhead
            }
            SyncStatus::Renamed => 256, // Just metadata
            _ => 0,
        })
        .sum()
}

// ═══════════════════════════════════════════════════════════════════════════════
// SYNC EXECUTOR
// ═══════════════════════════════════════════════════════════════════════════════

/// Trait for filesystem operations during sync.
pub trait SyncFilesystem {
    /// Read file contents.
    fn read_file(&self, path: &str) -> DeltaResult<Vec<u8>>;

    /// Write file contents.
    fn write_file(&mut self, path: &str, data: &[u8]) -> DeltaResult<()>;

    /// Delete file.
    fn delete_file(&mut self, path: &str) -> DeltaResult<()>;

    /// Rename file.
    fn rename_file(&mut self, from: &str, to: &str) -> DeltaResult<()>;

    /// Get file info.
    fn stat_file(&self, path: &str) -> DeltaResult<FileInfo>;

    /// List files in directory.
    fn list_files(&self, path: &str) -> DeltaResult<Vec<FileInfo>>;
}

/// Execute a sync plan.
///
/// # Arguments
/// * `plan` - Sync plan to execute
/// * `source_fs` - Source filesystem
/// * `dest_fs` - Destination filesystem
/// * `progress_cb` - Optional progress callback
///
/// # Returns
/// Final sync progress
pub fn execute_sync<S, D, F>(
    plan: &SyncPlan,
    source_fs: &S,
    dest_fs: &mut D,
    mut progress_cb: Option<F>,
    start_time: u64,
) -> DeltaResult<SyncProgress>
where
    S: SyncFilesystem,
    D: SyncFilesystem,
    F: FnMut(&SyncProgress),
{
    let total_files = plan.file_count() as u64;
    let total_bytes = plan.transfer_bytes();
    let mut progress = SyncProgress::new(total_files, total_bytes, start_time);

    for entry in &plan.entries {
        match entry.status {
            SyncStatus::Unchanged => {
                // Nothing to do
            }

            SyncStatus::New => {
                // Copy full file
                let data = source_fs.read_file(&entry.path)?;
                dest_fs.write_file(&entry.path, &data)?;
                progress.update(&entry.path, data.len() as u64, start_time);
            }

            SyncStatus::Modified => {
                // Compute and apply delta
                let old_data = dest_fs.read_file(&entry.path)?;
                let new_data = source_fs.read_file(&entry.path)?;

                let delta = compute_file_delta(&old_data, &new_data)?;
                let result = apply_file_delta(&old_data, &delta)?;

                dest_fs.write_file(&entry.path, &result)?;
                progress.update(&entry.path, delta.transfer_size(), start_time);
            }

            SyncStatus::Deleted => {
                dest_fs.delete_file(&entry.path)?;
                progress.update(&entry.path, 0, start_time);
            }

            SyncStatus::Renamed => {
                if let Some(original) = &entry.original_path {
                    dest_fs.rename_file(original, &entry.path)?;
                }
                progress.update(&entry.path, 0, start_time);
            }
        }

        if let Some(ref mut cb) = progress_cb {
            cb(&progress);
        }
    }

    Ok(progress)
}

// ═══════════════════════════════════════════════════════════════════════════════
// IN-MEMORY FILESYSTEM (FOR TESTING)
// ═══════════════════════════════════════════════════════════════════════════════

/// In-memory filesystem for testing.
#[derive(Debug, Clone, Default)]
pub struct MemoryFs {
    files: alloc::collections::BTreeMap<String, (Vec<u8>, u64)>,
}

impl MemoryFs {
    /// Create a new empty memory filesystem.
    pub fn new() -> Self {
        Self {
            files: alloc::collections::BTreeMap::new(),
        }
    }

    /// Add a file with specified mtime.
    pub fn add_file(&mut self, path: &str, data: &[u8], mtime: u64) {
        self.files.insert(path.to_string(), (data.to_vec(), mtime));
    }

    /// Get all file paths.
    pub fn paths(&self) -> Vec<&String> {
        self.files.keys().collect()
    }

    /// Check if file exists.
    pub fn exists(&self, path: &str) -> bool {
        self.files.contains_key(path)
    }
}

impl SyncFilesystem for MemoryFs {
    fn read_file(&self, path: &str) -> DeltaResult<Vec<u8>> {
        self.files
            .get(path)
            .map(|(data, _)| data.clone())
            .ok_or_else(|| DeltaError::SourceNotFound(path.to_string()))
    }

    fn write_file(&mut self, path: &str, data: &[u8]) -> DeltaResult<()> {
        let mtime = self.files.get(path).map(|(_, m)| *m + 1).unwrap_or(1);
        self.files.insert(path.to_string(), (data.to_vec(), mtime));
        Ok(())
    }

    fn delete_file(&mut self, path: &str) -> DeltaResult<()> {
        self.files.remove(path);
        Ok(())
    }

    fn rename_file(&mut self, from: &str, to: &str) -> DeltaResult<()> {
        if let Some(entry) = self.files.remove(from) {
            self.files.insert(to.to_string(), entry);
        }
        Ok(())
    }

    fn stat_file(&self, path: &str) -> DeltaResult<FileInfo> {
        self.files
            .get(path)
            .map(|(data, mtime)| {
                let checksum = file_checksum(data);
                FileInfo::new(path, data.len() as u64, *mtime, checksum)
            })
            .ok_or_else(|| DeltaError::SourceNotFound(path.to_string()))
    }

    fn list_files(&self, _path: &str) -> DeltaResult<Vec<FileInfo>> {
        Ok(self
            .files
            .iter()
            .map(|(path, (data, mtime))| {
                let checksum = file_checksum(data);
                FileInfo::new(path, data.len() as u64, *mtime, checksum)
            })
            .collect())
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// TESTS
// ═══════════════════════════════════════════════════════════════════════════════

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

    fn make_file_info(path: &str, data: &[u8], mtime: u64) -> FileInfo {
        FileInfo::new(path, data.len() as u64, mtime, file_checksum(data))
    }

    #[test]
    fn test_file_info_matches() {
        let data = b"test data";
        let info1 = make_file_info("/file.txt", data, 1000);
        let info2 = make_file_info("/file.txt", data, 2000);

        assert!(info1.matches(&info2)); // Same content

        let info3 = make_file_info("/file.txt", b"different", 1000);
        assert!(!info1.matches(&info3)); // Different content
    }

    #[test]
    fn test_file_info_is_newer() {
        let info1 = make_file_info("/file.txt", b"data", 1000);
        let info2 = make_file_info("/file.txt", b"data", 2000);

        assert!(info2.is_newer_than(&info1));
        assert!(!info1.is_newer_than(&info2));
    }

    #[test]
    fn test_plan_sync_no_changes() {
        let data = b"same content";
        let source = vec![make_file_info("/file.txt", data, 1000)];
        let dest = vec![make_file_info("/file.txt", data, 1000)];

        let plan = plan_sync("/src", "/dst", &source, &dest, 0);

        assert!(plan.is_empty());
        assert_eq!(plan.count_by_status(SyncStatus::Unchanged), 1);
    }

    #[test]
    fn test_plan_sync_new_file() {
        let source = vec![make_file_info("/new.txt", b"new file", 1000)];
        let dest = vec![];

        let plan = plan_sync("/src", "/dst", &source, &dest, 0);

        assert_eq!(plan.count_by_status(SyncStatus::New), 1);
        assert_eq!(plan.new_files()[0].path, "/new.txt");
    }

    #[test]
    fn test_plan_sync_modified_file() {
        let source = vec![make_file_info("/file.txt", b"new content", 2000)];
        let dest = vec![make_file_info("/file.txt", b"old content", 1000)];

        let plan = plan_sync("/src", "/dst", &source, &dest, 0);

        assert_eq!(plan.count_by_status(SyncStatus::Modified), 1);
    }

    #[test]
    fn test_plan_sync_deleted_file() {
        let source = vec![];
        let dest = vec![make_file_info("/old.txt", b"delete me", 1000)];

        let plan = plan_sync("/src", "/dst", &source, &dest, 0);

        assert_eq!(plan.count_by_status(SyncStatus::Deleted), 1);
    }

    #[test]
    fn test_plan_sync_renamed_file() {
        let data = b"same content different name";
        let source = vec![make_file_info("/new_name.txt", data, 2000)];
        let dest = vec![make_file_info("/old_name.txt", data, 1000)];

        let plan = plan_sync("/src", "/dst", &source, &dest, 0);

        assert_eq!(plan.count_by_status(SyncStatus::Renamed), 1);
        let renamed = &plan.renamed_files()[0];
        assert_eq!(renamed.path, "/new_name.txt");
        assert_eq!(renamed.original_path.as_deref(), Some("/old_name.txt"));
    }

    #[test]
    fn test_compute_file_delta() {
        let old = b"old file content here";
        let new = b"new file content here";

        let delta = compute_file_delta(old, new).unwrap();
        let result = apply_file_delta(old, &delta).unwrap();

        assert_eq!(&result, new);
    }

    #[test]
    fn test_compute_new_file_delta() {
        let data = b"brand new file";
        let delta = compute_new_file_delta(data);

        assert!(delta.is_full_replace());
    }

    #[test]
    fn test_estimate_transfer_size() {
        let mut plan = SyncPlan::new("/src", "/dst", 0);

        plan.add_entry(SyncEntry::new("/new.txt", 1000, 1, [0; 4], SyncStatus::New));
        plan.add_entry(SyncEntry::new(
            "/mod.txt",
            5000,
            2,
            [0; 4],
            SyncStatus::Modified,
        ));

        let estimate = estimate_transfer_size(&plan);
        assert!(estimate > 1000); // At least the new file
        assert!(estimate < 6000); // Less than full sync
    }

    #[test]
    fn test_memory_fs_basic() {
        let mut fs = MemoryFs::new();

        fs.add_file("/test.txt", b"hello world", 1000);
        assert!(fs.exists("/test.txt"));

        let data = fs.read_file("/test.txt").unwrap();
        assert_eq!(&data, b"hello world");

        let info = fs.stat_file("/test.txt").unwrap();
        assert_eq!(info.size, 11);
    }

    #[test]
    fn test_memory_fs_write() {
        let mut fs = MemoryFs::new();

        fs.write_file("/new.txt", b"new content").unwrap();
        assert!(fs.exists("/new.txt"));

        let data = fs.read_file("/new.txt").unwrap();
        assert_eq!(&data, b"new content");
    }

    #[test]
    fn test_memory_fs_delete() {
        let mut fs = MemoryFs::new();

        fs.add_file("/delete_me.txt", b"temp", 1000);
        assert!(fs.exists("/delete_me.txt"));

        fs.delete_file("/delete_me.txt").unwrap();
        assert!(!fs.exists("/delete_me.txt"));
    }

    #[test]
    fn test_memory_fs_rename() {
        let mut fs = MemoryFs::new();

        fs.add_file("/old.txt", b"content", 1000);
        fs.rename_file("/old.txt", "/new.txt").unwrap();

        assert!(!fs.exists("/old.txt"));
        assert!(fs.exists("/new.txt"));

        let data = fs.read_file("/new.txt").unwrap();
        assert_eq!(&data, b"content");
    }

    #[test]
    fn test_execute_sync_new_files() {
        let mut source = MemoryFs::new();
        let mut dest = MemoryFs::new();

        source.add_file("/file1.txt", b"content one", 1000);
        source.add_file("/file2.txt", b"content two", 1000);

        let source_files = source.list_files("/").unwrap();
        let dest_files = dest.list_files("/").unwrap();
        let plan = plan_sync("/src", "/dst", &source_files, &dest_files, 0);

        let progress =
            execute_sync(&plan, &source, &mut dest, None::<fn(&SyncProgress)>, 0).unwrap();

        assert!(dest.exists("/file1.txt"));
        assert!(dest.exists("/file2.txt"));
        assert_eq!(progress.files_done, 2);
    }

    #[test]
    fn test_execute_sync_modified_files() {
        let mut source = MemoryFs::new();
        let mut dest = MemoryFs::new();

        source.add_file("/file.txt", b"new content here", 2000);
        dest.add_file("/file.txt", b"old content here", 1000);

        let source_files = source.list_files("/").unwrap();
        let dest_files = dest.list_files("/").unwrap();
        let plan = plan_sync("/src", "/dst", &source_files, &dest_files, 0);

        execute_sync(&plan, &source, &mut dest, None::<fn(&SyncProgress)>, 0).unwrap();

        let result = dest.read_file("/file.txt").unwrap();
        assert_eq!(&result, b"new content here");
    }

    #[test]
    fn test_execute_sync_deleted_files() {
        let mut source = MemoryFs::new();
        let mut dest = MemoryFs::new();

        dest.add_file("/delete_me.txt", b"old file", 1000);

        let source_files = source.list_files("/").unwrap();
        let dest_files = dest.list_files("/").unwrap();
        let plan = plan_sync("/src", "/dst", &source_files, &dest_files, 0);

        execute_sync(&plan, &source, &mut dest, None::<fn(&SyncProgress)>, 0).unwrap();

        assert!(!dest.exists("/delete_me.txt"));
    }

    #[test]
    fn test_execute_sync_renamed_files() {
        let mut source = MemoryFs::new();
        let mut dest = MemoryFs::new();

        let content = b"same content";
        source.add_file("/new_name.txt", content, 2000);
        dest.add_file("/old_name.txt", content, 1000);

        let source_files = source.list_files("/").unwrap();
        let dest_files = dest.list_files("/").unwrap();
        let plan = plan_sync("/src", "/dst", &source_files, &dest_files, 0);

        execute_sync(&plan, &source, &mut dest, None::<fn(&SyncProgress)>, 0).unwrap();

        assert!(!dest.exists("/old_name.txt"));
        assert!(dest.exists("/new_name.txt"));
    }

    #[test]
    fn test_full_sync_scenario() {
        let mut source = MemoryFs::new();
        let mut dest = MemoryFs::new();

        // Source files
        source.add_file("/unchanged.txt", b"same", 1000);
        source.add_file("/modified.txt", b"new version", 2000);
        source.add_file("/new.txt", b"brand new", 3000);
        source.add_file("/renamed.txt", b"rename this", 2000);

        // Dest files
        dest.add_file("/unchanged.txt", b"same", 1000);
        dest.add_file("/modified.txt", b"old version", 1000);
        dest.add_file("/to_delete.txt", b"delete me", 1000);
        dest.add_file("/old_name.txt", b"rename this", 1000);

        let source_files = source.list_files("/").unwrap();
        let dest_files = dest.list_files("/").unwrap();
        let plan = plan_sync("/src", "/dst", &source_files, &dest_files, 0);

        assert_eq!(plan.count_by_status(SyncStatus::Unchanged), 1);
        assert_eq!(plan.count_by_status(SyncStatus::Modified), 1);
        assert_eq!(plan.count_by_status(SyncStatus::New), 1);
        assert_eq!(plan.count_by_status(SyncStatus::Deleted), 1);
        assert_eq!(plan.count_by_status(SyncStatus::Renamed), 1);

        execute_sync(&plan, &source, &mut dest, None::<fn(&SyncProgress)>, 0).unwrap();

        // Verify final state
        assert!(dest.exists("/unchanged.txt"));
        assert!(dest.exists("/modified.txt"));
        assert!(dest.exists("/new.txt"));
        assert!(dest.exists("/renamed.txt"));
        assert!(!dest.exists("/to_delete.txt"));
        assert!(!dest.exists("/old_name.txt"));

        // Verify content
        assert_eq!(dest.read_file("/modified.txt").unwrap(), b"new version");
        assert_eq!(dest.read_file("/new.txt").unwrap(), b"brand new");
    }
}