|
1 | | -use crate::utils::{archive::for_each_entry, setup}; |
| 1 | +use crate::utils::{ |
| 2 | + archive::{create_test_archive, get_archive_entry_names}, |
| 3 | + setup, |
| 4 | +}; |
2 | 5 | use assert_cmd::cargo::cargo_bin_cmd; |
3 | | -use pna::{Archive, EntryBuilder, WriteOptions}; |
4 | 6 | use std::collections::HashSet; |
5 | 7 | use std::fs; |
6 | | -use std::io::Write; |
7 | | -use std::path::Path; |
8 | | - |
9 | | -fn create_test_archive(path: &Path, entries: &[(&str, &str)]) { |
10 | | - if let Some(parent) = path.parent() { |
11 | | - fs::create_dir_all(parent).unwrap(); |
12 | | - } |
13 | | - let file = fs::File::create(path).unwrap(); |
14 | | - let mut writer = Archive::write_header(file).unwrap(); |
15 | | - for (name, contents) in entries { |
16 | | - writer |
17 | | - .add_entry({ |
18 | | - let mut builder = |
19 | | - EntryBuilder::new_file((*name).into(), WriteOptions::builder().build()) |
20 | | - .unwrap(); |
21 | | - builder.write_all(contents.as_bytes()).unwrap(); |
22 | | - builder.build().unwrap() |
23 | | - }) |
24 | | - .unwrap(); |
25 | | - } |
26 | | - writer.finalize().unwrap(); |
27 | | -} |
28 | | - |
29 | | -fn get_archive_entry_names(path: &Path) -> Vec<String> { |
30 | | - let mut names = Vec::new(); |
31 | | - for_each_entry(path, |entry| { |
32 | | - names.push(entry.header().path().to_string()); |
33 | | - }) |
34 | | - .unwrap(); |
35 | | - names |
36 | | -} |
37 | 8 |
|
38 | 9 | /// Precondition: Archive source.pna contains file a.txt. Directory sub/ contains b.txt. |
39 | 10 | /// Action: Create with `@source.pna -C sub b.txt` -- archive inclusion before -C. |
|
0 commit comments