1use crate::ExtractionError;
7use crate::ProgressCallback;
8use crate::Result;
9use crate::creation::config::CreationConfig;
10use crate::creation::filters;
11use crate::creation::report::CreationReport;
12use crate::creation::walker::EntryType;
13use crate::creation::walker::FilteredWalker;
14use crate::creation::walker::collect_entries;
15use std::fs::File;
16use std::io::Read;
17use std::io::Seek;
18use std::io::Write;
19use std::path::Path;
20use zip::CompressionMethod;
21use zip::ZipWriter;
22use zip::write::SimpleFileOptions;
23
24#[allow(dead_code)] pub fn create_zip<P: AsRef<Path>, Q: AsRef<Path>>(
47 output: P,
48 sources: &[Q],
49 config: &CreationConfig,
50) -> Result<CreationReport> {
51 let file = File::create(output.as_ref())?;
52 create_zip_internal(file, sources, config)
53}
54
55#[allow(dead_code)] pub fn create_zip_with_progress<P: AsRef<Path>, Q: AsRef<Path>>(
130 output: P,
131 sources: &[Q],
132 config: &CreationConfig,
133 progress: &mut dyn ProgressCallback,
134) -> Result<CreationReport> {
135 let file = File::create(output.as_ref())?;
136 create_zip_internal_with_progress(file, sources, config, progress)
137}
138
139fn create_zip_internal_with_progress<W: Write + Seek, P: AsRef<Path>>(
141 writer: W,
142 sources: &[P],
143 config: &CreationConfig,
144 progress: &mut dyn ProgressCallback,
145) -> Result<CreationReport> {
146 let mut zip = ZipWriter::new(writer);
147 let mut report = CreationReport::default();
148 let start = std::time::Instant::now();
149
150 let options = if config.compression_level == Some(0) {
152 SimpleFileOptions::default().compression_method(CompressionMethod::Stored)
153 } else {
154 let level = config.compression_level.unwrap_or(6);
155 SimpleFileOptions::default()
156 .compression_method(CompressionMethod::Deflated)
157 .compression_level(Some(i64::from(level)))
158 };
159
160 let entries = collect_entries(sources, config)?;
162 let total_entries = entries.len();
163
164 let mut buffer = vec![0u8; 64 * 1024]; for (idx, entry) in entries.iter().enumerate() {
168 let current_entry = idx + 1;
169
170 match &entry.entry_type {
171 EntryType::File => {
172 progress.on_entry_start(&entry.archive_path, total_entries, current_entry);
173 add_file_to_zip_with_progress_and_buffer(
174 &mut zip,
175 &entry.path,
176 &entry.archive_path,
177 config,
178 &mut report,
179 &options,
180 progress,
181 &mut buffer,
182 )?;
183 progress.on_entry_complete(&entry.archive_path);
184 }
185 EntryType::Directory => {
186 progress.on_entry_start(&entry.archive_path, total_entries, current_entry);
187 if !entry.archive_path.as_os_str().is_empty() {
189 let dir_path = format!("{}/", normalize_zip_path(&entry.archive_path)?);
190 zip.add_directory(&dir_path, options).map_err(|e| {
191 std::io::Error::other(format!("failed to add directory: {e}"))
192 })?;
193 report.directories_added += 1;
194 }
195 progress.on_entry_complete(&entry.archive_path);
196 }
197 EntryType::Symlink { .. } => {
198 progress.on_entry_start(&entry.archive_path, total_entries, current_entry);
199 if !config.follow_symlinks {
200 report.files_skipped += 1;
201 report.add_warning(format!("Skipped symlink: {}", entry.path.display()));
202 }
203 progress.on_entry_complete(&entry.archive_path);
204 }
205 }
206 }
207
208 zip.finish()
210 .map_err(|e| std::io::Error::other(format!("failed to finish ZIP archive: {e}")))?;
211
212 report.duration = start.elapsed();
213
214 progress.on_complete();
215
216 Ok(report)
217}
218
219fn create_zip_internal<W: Write + Seek, P: AsRef<Path>>(
223 writer: W,
224 sources: &[P],
225 config: &CreationConfig,
226) -> Result<CreationReport> {
227 let mut zip = ZipWriter::new(writer);
228 let mut report = CreationReport::default();
229 let start = std::time::Instant::now();
230
231 let options = if config.compression_level == Some(0) {
233 SimpleFileOptions::default().compression_method(CompressionMethod::Stored)
234 } else {
235 let level = config.compression_level.unwrap_or(6);
237 SimpleFileOptions::default()
238 .compression_method(CompressionMethod::Deflated)
239 .compression_level(Some(i64::from(level)))
240 };
241
242 for source in sources {
243 let path = source.as_ref();
244
245 if !path.exists() {
247 return Err(ExtractionError::SourceNotFound {
248 path: path.to_path_buf(),
249 });
250 }
251
252 if path.is_dir() {
254 add_directory_to_zip(&mut zip, path, config, &mut report, &options)?;
255 } else {
256 let archive_path =
258 filters::compute_archive_path(path, path.parent().unwrap_or(path), config)?;
259 add_file_to_zip(&mut zip, path, &archive_path, config, &mut report, &options)?;
260 }
261 }
262
263 zip.finish()
265 .map_err(|e| std::io::Error::other(format!("failed to finish ZIP archive: {e}")))?;
266
267 report.duration = start.elapsed();
268
269 Ok(report)
270}
271
272fn add_directory_to_zip<W: Write + Seek>(
274 zip: &mut ZipWriter<W>,
275 dir: &Path,
276 config: &CreationConfig,
277 report: &mut CreationReport,
278 options: &SimpleFileOptions,
279) -> Result<()> {
280 let walker = FilteredWalker::new(dir, config);
281
282 for entry in walker.walk() {
283 let entry = entry?;
284
285 match entry.entry_type {
286 EntryType::File => {
287 add_file_to_zip(
288 zip,
289 &entry.path,
290 &entry.archive_path,
291 config,
292 report,
293 options,
294 )?;
295 }
296 EntryType::Directory => {
297 let dir_path = format!("{}/", normalize_zip_path(&entry.archive_path)?);
299 zip.add_directory(&dir_path, *options)
300 .map_err(|e| std::io::Error::other(format!("failed to add directory: {e}")))?;
301 report.directories_added += 1;
302 }
303 EntryType::Symlink { .. } => {
304 if !config.follow_symlinks {
305 report.files_skipped += 1;
308 report.add_warning(format!("Skipped symlink: {}", entry.path.display()));
309 }
310 }
311 }
312 }
313
314 Ok(())
315}
316
317fn add_file_to_zip<W: Write + Seek>(
319 zip: &mut ZipWriter<W>,
320 file_path: &Path,
321 archive_path: &Path,
322 config: &CreationConfig,
323 report: &mut CreationReport,
324 options: &SimpleFileOptions,
325) -> Result<()> {
326 let mut file = File::open(file_path)?;
327 let metadata = file.metadata()?;
328 let size = metadata.len();
329
330 if let Some(max_size) = config.max_file_size
332 && size > max_size
333 {
334 report.files_skipped += 1;
335 report.add_warning(format!(
336 "Skipped file (too large): {} ({} bytes)",
337 file_path.display(),
338 size
339 ));
340 return Ok(());
341 }
342
343 let file_options = if config.preserve_permissions {
345 #[cfg(unix)]
346 {
347 use std::os::unix::fs::PermissionsExt;
348 options.unix_permissions(metadata.permissions().mode())
349 }
350 #[cfg(not(unix))]
351 {
352 *options
353 }
354 } else {
355 *options
356 };
357
358 let archive_name = normalize_zip_path(archive_path)?;
360
361 zip.start_file(&archive_name, file_options)
362 .map_err(|e| std::io::Error::other(format!("failed to start file in ZIP: {e}")))?;
363
364 let mut buffer = vec![0u8; 64 * 1024]; let mut bytes_written = 0u64;
367 loop {
368 let bytes_read = file.read(&mut buffer)?;
369 if bytes_read == 0 {
370 break;
371 }
372 zip.write_all(&buffer[..bytes_read])?;
373 bytes_written += bytes_read as u64;
374 }
375
376 report.files_added += 1;
377 report.bytes_written += bytes_written;
378
379 Ok(())
380}
381
382#[allow(clippy::too_many_arguments)]
385fn add_file_to_zip_with_progress_and_buffer<W: Write + Seek>(
386 zip: &mut ZipWriter<W>,
387 file_path: &Path,
388 archive_path: &Path,
389 config: &CreationConfig,
390 report: &mut CreationReport,
391 options: &SimpleFileOptions,
392 progress: &mut dyn ProgressCallback,
393 buffer: &mut [u8],
394) -> Result<()> {
395 let mut file = File::open(file_path)?;
396 let metadata = file.metadata()?;
397 let size = metadata.len();
398
399 if let Some(max_size) = config.max_file_size
401 && size > max_size
402 {
403 report.files_skipped += 1;
404 report.add_warning(format!(
405 "Skipped file (too large): {} ({} bytes)",
406 file_path.display(),
407 size
408 ));
409 return Ok(());
410 }
411
412 let file_options = if config.preserve_permissions {
414 #[cfg(unix)]
415 {
416 use std::os::unix::fs::PermissionsExt;
417 options.unix_permissions(metadata.permissions().mode())
418 }
419 #[cfg(not(unix))]
420 {
421 *options
422 }
423 } else {
424 *options
425 };
426
427 let archive_name = normalize_zip_path(archive_path)?;
428
429 zip.start_file(&archive_name, file_options)
430 .map_err(|e| std::io::Error::other(format!("failed to start file in ZIP: {e}")))?;
431
432 let mut bytes_written = 0u64;
434 loop {
435 let bytes_read = file.read(buffer)?;
436 if bytes_read == 0 {
437 break;
438 }
439 zip.write_all(&buffer[..bytes_read])?;
440 bytes_written += bytes_read as u64;
441 progress.on_bytes_written(bytes_read as u64);
442 }
443
444 report.files_added += 1;
445 report.bytes_written += bytes_written;
446
447 Ok(())
448}
449
450fn normalize_zip_path(path: &Path) -> Result<String> {
455 let path_str = path.to_str().ok_or_else(|| {
457 ExtractionError::Io(std::io::Error::other(format!(
458 "path is not valid UTF-8: {}",
459 path.display()
460 )))
461 })?;
462
463 #[cfg(windows)]
465 let normalized = path_str.replace('\\', "/");
466
467 #[cfg(not(windows))]
468 let normalized = path_str.to_string();
469
470 Ok(normalized)
471}
472
473#[cfg(test)]
474#[allow(clippy::unwrap_used)] mod tests {
476 use super::*;
477 use std::fs;
478 use tempfile::TempDir;
479
480 #[test]
481 fn test_create_zip_single_file() {
482 let temp = TempDir::new().unwrap();
483 let output = temp.path().join("output.zip");
484
485 let source_dir = TempDir::new().unwrap();
487 fs::write(source_dir.path().join("test.txt"), "Hello ZIP").unwrap();
488
489 let config = CreationConfig::default()
490 .with_exclude_patterns(vec![])
491 .with_include_hidden(true);
492
493 let report = create_zip(&output, &[source_dir.path().join("test.txt")], &config).unwrap();
494
495 assert_eq!(report.files_added, 1);
496 assert!(report.bytes_written > 0);
497 assert!(output.exists());
498 }
499
500 #[test]
501 fn test_create_zip_directory() {
502 let temp = TempDir::new().unwrap();
503 let output = temp.path().join("output.zip");
504
505 let source_dir = TempDir::new().unwrap();
507 fs::write(source_dir.path().join("file1.txt"), "content1").unwrap();
508 fs::write(source_dir.path().join("file2.txt"), "content2").unwrap();
509 fs::create_dir(source_dir.path().join("subdir")).unwrap();
510 fs::write(source_dir.path().join("subdir/file3.txt"), "content3").unwrap();
511
512 let config = CreationConfig::default()
513 .with_exclude_patterns(vec![])
514 .with_include_hidden(true);
515
516 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
517
518 assert_eq!(report.files_added, 3);
520 assert_eq!(report.directories_added, 2);
522 assert!(output.exists());
523 }
524
525 #[test]
526 fn test_create_zip_compression() {
527 let temp = TempDir::new().unwrap();
528 let output = temp.path().join("output.zip");
529
530 let source_dir = TempDir::new().unwrap();
532 fs::write(source_dir.path().join("test.txt"), "a".repeat(1000)).unwrap();
533
534 let config = CreationConfig::default()
535 .with_exclude_patterns(vec![])
536 .with_compression_level(9);
537
538 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
539
540 assert_eq!(report.files_added, 1);
541 assert!(output.exists());
542
543 let data = fs::read(&output).unwrap();
545 assert_eq!(&data[0..4], b"PK\x03\x04"); }
547
548 #[test]
549 fn test_create_zip_compression_levels() {
550 let temp = TempDir::new().unwrap();
551
552 let source_dir = TempDir::new().unwrap();
554 fs::write(source_dir.path().join("test.txt"), "a".repeat(10000)).unwrap();
555
556 for level in [1, 6, 9] {
558 let output = temp.path().join(format!("output_{level}.zip"));
559 let config = CreationConfig::default()
560 .with_exclude_patterns(vec![])
561 .with_compression_level(level);
562
563 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
564 assert_eq!(report.files_added, 1);
565 assert!(output.exists());
566 }
567 }
568
569 #[test]
570 fn test_create_zip_explicit_directories() {
571 let temp = TempDir::new().unwrap();
572 let output = temp.path().join("output.zip");
573
574 let source_dir = TempDir::new().unwrap();
576 fs::create_dir(source_dir.path().join("dir1")).unwrap();
577 fs::create_dir(source_dir.path().join("dir1/dir2")).unwrap();
578 fs::write(source_dir.path().join("dir1/dir2/file.txt"), "content").unwrap();
579
580 let config = CreationConfig::default()
581 .with_exclude_patterns(vec![])
582 .with_include_hidden(true);
583
584 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
585
586 assert!(report.directories_added >= 2); assert!(output.exists());
588
589 let file = File::open(&output).unwrap();
591 let mut archive = zip::ZipArchive::new(file).unwrap();
592
593 let mut dir_entries = 0;
594 for i in 0..archive.len() {
595 let entry = archive.by_index(i).unwrap();
596 if entry.is_dir() {
597 dir_entries += 1;
598 assert!(
599 entry.name().ends_with('/'),
600 "Directory entry should end with /"
601 );
602 }
603 }
604 assert!(dir_entries >= 2, "Expected at least 2 directory entries");
605 }
606
607 #[cfg(unix)]
608 #[test]
609 fn test_create_zip_preserves_permissions() {
610 use std::os::unix::fs::PermissionsExt;
611
612 let temp = TempDir::new().unwrap();
613 let output = temp.path().join("output.zip");
614
615 let source_dir = TempDir::new().unwrap();
617 let file_path = source_dir.path().join("test.txt");
618 fs::write(&file_path, "content").unwrap();
619 fs::set_permissions(&file_path, fs::Permissions::from_mode(0o755)).unwrap();
620
621 let config = CreationConfig::default()
622 .with_exclude_patterns(vec![])
623 .with_preserve_permissions(true);
624
625 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
626 assert_eq!(report.files_added, 1);
627
628 let file = File::open(&output).unwrap();
630 let mut archive = zip::ZipArchive::new(file).unwrap();
631
632 for i in 0..archive.len() {
633 let entry = archive.by_index(i).unwrap();
634 if entry.name().contains("test.txt")
635 && let Some(mode) = entry.unix_mode()
636 {
637 assert_eq!(mode & 0o777, 0o755, "Permissions should be preserved");
638 }
639 }
640 }
641
642 #[test]
643 fn test_create_zip_report_statistics() {
644 let temp = TempDir::new().unwrap();
645 let output = temp.path().join("output.zip");
646
647 let source_dir = TempDir::new().unwrap();
649 fs::write(source_dir.path().join("file1.txt"), "content1").unwrap();
650 fs::write(source_dir.path().join("file2.txt"), "content2").unwrap();
651 fs::create_dir(source_dir.path().join("subdir")).unwrap();
652 fs::write(source_dir.path().join("subdir/file3.txt"), "content3").unwrap();
653
654 let config = CreationConfig::default()
655 .with_exclude_patterns(vec![])
656 .with_include_hidden(true);
657
658 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
659
660 assert_eq!(report.files_added, 3);
661 assert!(report.directories_added >= 1);
662 assert_eq!(report.files_skipped, 0);
663 assert!(!report.has_warnings());
664 assert!(report.duration.as_nanos() > 0);
665 }
666
667 #[test]
668 fn test_create_zip_roundtrip() {
669 let temp = TempDir::new().unwrap();
670 let output = temp.path().join("output.zip");
671
672 let source_dir = TempDir::new().unwrap();
674 fs::write(source_dir.path().join("file1.txt"), "content1").unwrap();
675 fs::create_dir(source_dir.path().join("subdir")).unwrap();
676 fs::write(source_dir.path().join("subdir/file2.txt"), "content2").unwrap();
677
678 let config = CreationConfig::default()
679 .with_exclude_patterns(vec![])
680 .with_include_hidden(true);
681
682 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
684 assert!(report.files_added >= 2);
685
686 let file = File::open(&output).unwrap();
688 let mut archive = zip::ZipArchive::new(file).unwrap();
689
690 let extract_dir = TempDir::new().unwrap();
691
692 for i in 0..archive.len() {
693 let mut entry = archive.by_index(i).unwrap();
694 let outpath = extract_dir.path().join(entry.name());
695
696 if entry.is_dir() {
697 fs::create_dir_all(&outpath).unwrap();
698 } else {
699 if let Some(parent) = outpath.parent() {
700 fs::create_dir_all(parent).unwrap();
701 }
702 let mut outfile = File::create(&outpath).unwrap();
703 std::io::copy(&mut entry, &mut outfile).unwrap();
704 }
705 }
706
707 let extracted1 = fs::read_to_string(extract_dir.path().join("file1.txt")).unwrap();
709 assert_eq!(extracted1, "content1");
710
711 let extracted2 = fs::read_to_string(extract_dir.path().join("subdir/file2.txt")).unwrap();
712 assert_eq!(extracted2, "content2");
713 }
714
715 #[test]
716 fn test_create_zip_forward_slashes() {
717 let temp = TempDir::new().unwrap();
718 let output = temp.path().join("output.zip");
719
720 let source_dir = TempDir::new().unwrap();
722 fs::create_dir(source_dir.path().join("dir1")).unwrap();
723 fs::write(source_dir.path().join("dir1/file.txt"), "content").unwrap();
724
725 let config = CreationConfig::default()
726 .with_exclude_patterns(vec![])
727 .with_include_hidden(true);
728
729 create_zip(&output, &[source_dir.path()], &config).unwrap();
730
731 let file = File::open(&output).unwrap();
733 let mut archive = zip::ZipArchive::new(file).unwrap();
734
735 for i in 0..archive.len() {
736 let entry = archive.by_index(i).unwrap();
737 let name = entry.name();
738 assert!(
740 !name.contains('\\'),
741 "ZIP path should use forward slashes: {name}"
742 );
743 if name.contains("dir1") && name.contains("file") {
745 assert!(name.contains("dir1/file"), "Expected forward slash in path");
746 }
747 }
748 }
749
750 #[test]
751 fn test_create_zip_source_not_found() {
752 let temp = TempDir::new().unwrap();
753 let output = temp.path().join("output.zip");
754
755 let config = CreationConfig::default();
756 let result = create_zip(&output, &[Path::new("/nonexistent/path")], &config);
757
758 assert!(result.is_err());
759 assert!(matches!(
760 result.unwrap_err(),
761 ExtractionError::SourceNotFound { .. }
762 ));
763 }
764
765 #[test]
766 fn test_normalize_zip_path() {
767 let path = Path::new("dir/file.txt");
769 let normalized = normalize_zip_path(path).unwrap();
770 assert_eq!(normalized, "dir/file.txt");
771
772 let path = Path::new("file.txt");
774 let normalized = normalize_zip_path(path).unwrap();
775 assert_eq!(normalized, "file.txt");
776
777 let path = Path::new("a/b/c/file.txt");
779 let normalized = normalize_zip_path(path).unwrap();
780 assert_eq!(normalized, "a/b/c/file.txt");
781 }
782
783 #[cfg(windows)]
784 #[test]
785 fn test_normalize_zip_path_windows() {
786 let path = Path::new("dir\\file.txt");
788 let normalized = normalize_zip_path(path).unwrap();
789 assert_eq!(normalized, "dir/file.txt");
790
791 let path = Path::new("a\\b\\c\\file.txt");
793 let normalized = normalize_zip_path(path).unwrap();
794 assert_eq!(normalized, "a/b/c/file.txt");
795 }
796
797 #[test]
798 fn test_create_zip_max_file_size() {
799 let temp = TempDir::new().unwrap();
800 let output = temp.path().join("output.zip");
801
802 let source_dir = TempDir::new().unwrap();
804 fs::write(source_dir.path().join("small.txt"), "tiny").unwrap(); fs::write(source_dir.path().join("large.txt"), "a".repeat(1000)).unwrap(); let config = CreationConfig::default()
809 .with_exclude_patterns(vec![])
810 .with_max_file_size(Some(100));
811
812 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
813
814 assert_eq!(report.files_added, 1);
817 assert_eq!(report.files_skipped, 0);
818 }
819
820 #[cfg(unix)]
821 #[test]
822 fn test_create_zip_skips_symlinks() {
823 let temp = TempDir::new().unwrap();
824 let output = temp.path().join("output.zip");
825
826 let source_dir = TempDir::new().unwrap();
828 fs::write(source_dir.path().join("target.txt"), "content").unwrap();
829 std::os::unix::fs::symlink(
830 source_dir.path().join("target.txt"),
831 source_dir.path().join("link.txt"),
832 )
833 .unwrap();
834
835 let config = CreationConfig::default()
837 .with_exclude_patterns(vec![])
838 .with_include_hidden(true);
839
840 let report = create_zip(&output, &[source_dir.path()], &config).unwrap();
841
842 assert_eq!(report.files_added, 1);
844 assert_eq!(report.files_skipped, 1);
845 assert!(report.has_warnings());
846
847 let warning = &report.warnings[0];
848 assert!(warning.contains("Skipped symlink"));
849 }
850
851 #[test]
852 fn test_create_zip_with_progress_callback() {
853 #[derive(Debug, Default, Clone)]
854 struct TestProgress {
855 entries_started: Vec<String>,
856 entries_completed: Vec<String>,
857 bytes_written: u64,
858 completed: bool,
859 }
860
861 impl ProgressCallback for TestProgress {
862 fn on_entry_start(&mut self, path: &Path, _total: usize, _current: usize) {
863 self.entries_started
864 .push(path.to_string_lossy().to_string());
865 }
866
867 fn on_bytes_written(&mut self, bytes: u64) {
868 self.bytes_written += bytes;
869 }
870
871 fn on_entry_complete(&mut self, path: &Path) {
872 self.entries_completed
873 .push(path.to_string_lossy().to_string());
874 }
875
876 fn on_complete(&mut self) {
877 self.completed = true;
878 }
879 }
880
881 let temp = TempDir::new().unwrap();
882 let output = temp.path().join("output.zip");
883
884 let source_dir = TempDir::new().unwrap();
886 fs::write(source_dir.path().join("file1.txt"), "content1").unwrap();
887 fs::write(source_dir.path().join("file2.txt"), "content2").unwrap();
888 fs::create_dir(source_dir.path().join("subdir")).unwrap();
889 fs::write(source_dir.path().join("subdir/file3.txt"), "content3").unwrap();
890
891 let config = CreationConfig::default()
892 .with_exclude_patterns(vec![])
893 .with_include_hidden(true);
894
895 let mut progress = TestProgress::default();
896
897 let report =
898 create_zip_with_progress(&output, &[source_dir.path()], &config, &mut progress)
899 .unwrap();
900
901 assert_eq!(report.files_added, 3);
903 assert!(report.directories_added >= 1);
904
905 assert!(
907 progress.entries_started.len() >= 3,
908 "Expected at least 3 entry starts, got {}",
909 progress.entries_started.len()
910 );
911 assert!(
912 progress.entries_completed.len() >= 3,
913 "Expected at least 3 entry completions, got {}",
914 progress.entries_completed.len()
915 );
916 assert!(
917 progress.bytes_written > 0,
918 "Expected bytes written > 0, got {}",
919 progress.bytes_written
920 );
921 assert!(progress.completed, "Expected on_complete to be called");
922
923 let has_file1 = progress
925 .entries_started
926 .iter()
927 .any(|p| p.contains("file1.txt"));
928 let has_file2 = progress
929 .entries_started
930 .iter()
931 .any(|p| p.contains("file2.txt"));
932 let has_file3 = progress
933 .entries_started
934 .iter()
935 .any(|p| p.contains("file3.txt"));
936
937 assert!(has_file1, "Expected file1.txt in progress callbacks");
938 assert!(has_file2, "Expected file2.txt in progress callbacks");
939 assert!(has_file3, "Expected file3.txt in progress callbacks");
940 }
941}