protofetch 0.1.21

A source dependency management tool for Protobuf.
Documentation
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
//! End-to-end test infrastructure.
//! Provides helpers to create real local git repositories, run the full
//! protofetch fetch pipeline, and snapshot the output directory.

use std::{
    collections::{BTreeMap, BTreeSet},
    error::Error,
    fs,
    path::{Path, PathBuf},
};

use git2::{build::CheckoutBuilder, IndexAddOption, Repository, Signature};
use insta::{assert_snapshot, Settings};
use protofetch::{DependencyUpdate, LockMode, LockUpdateMode, Protofetch};
use tempfile::TempDir;

/// A local git repository created by [`TestWorld::create_repo`].
pub struct TestRepo {
    /// Absolute filesystem path to the repository.
    path: PathBuf,
    /// Base path of the remotes temp dir — used to expand `<base>` in file content.
    remotes_path: PathBuf,
    /// All commits added so far, in order: `(branch, commit_hash)`.
    commits: Vec<(String, String)>,
}

struct FixtureCommit {
    repo: String,
    branch: String,
    index: usize,
    path: PathBuf,
}

impl TestRepo {
    /// Add a commit on `branch`, writing `files` into the working tree.
    ///
    /// If `branch` does not yet exist it is created from the most recent
    /// commit recorded in this repo (i.e. the tip of the last-used branch).
    /// Returns `&mut Self` for chaining.
    pub fn add_commit(&mut self, branch: &str, files: &[(&str, &str)]) -> &mut Self {
        let repo = Repository::open(&self.path).expect("open repo");
        let branch_ref = format!("refs/heads/{branch}");

        let parent = if let Ok(b) = repo.find_branch(branch, git2::BranchType::Local) {
            b.get().peel_to_commit().expect("peel to commit")
        } else {
            let (_, last_hash) = self.commits.last().expect("need at least one commit");
            let oid = git2::Oid::from_str(last_hash).expect("parse oid");
            let last = repo.find_commit(oid).expect("find commit");
            repo.branch(branch, &last, false).expect("create branch");
            last
        };

        repo.set_head(&branch_ref).expect("set HEAD");
        let mut checkout = CheckoutBuilder::new();
        checkout.force();
        repo.checkout_head(Some(&mut checkout))
            .expect("checkout branch");

        let base = self.remotes_path.to_string_lossy().replace('\\', "/");
        for (rel_path, content) in files {
            let abs = self.path.join(rel_path);
            if let Some(p) = abs.parent() {
                fs::create_dir_all(p).expect("create dir");
            }
            fs::write(&abs, content.replace("<base>", &base)).expect("write file");
        }

        let mut index = repo.index().expect("repo index");
        index
            .add_all(["*"], IndexAddOption::DEFAULT, None)
            .expect("git add");
        index.write().expect("write index");
        let tree_oid = index.write_tree().expect("write tree");
        let tree = repo.find_tree(tree_oid).expect("find tree");

        let sig = Signature::now("Test", "test@example.com").expect("signature");
        let commit_oid = repo
            .commit(Some(&branch_ref), &sig, &sig, "commit", &tree, &[&parent])
            .expect("commit");

        self.commits
            .push((branch.to_string(), commit_oid.to_string()));
        self
    }
}

/// Owns all temporary directories for one end-to-end test scenario.
pub struct TestWorld {
    /// Temp dir holding the "remote" source repos.
    remotes: TempDir,
    /// Temp dir used as the protofetch project root.
    project: TempDir,
    /// Temp dir used as the protofetch cache.
    cache: TempDir,
    /// All repos created by [`TestWorld::create_repo`], in creation order.
    repos: Vec<TestRepo>,
}

impl TestWorld {
    pub fn new() -> Self {
        Self {
            remotes: TempDir::new().expect("remotes TempDir"),
            project: TempDir::new().expect("project TempDir"),
            cache: TempDir::new().expect("cache TempDir"),
            repos: Vec::new(),
        }
    }

    /// Run a file-backed end-to-end fixture from `tests/e2e/<name>`.
    fn run(name: &str, lock_mode: LockMode) -> FetchResult {
        let fixture = Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("tests/e2e")
            .join(name);
        let mut world = Self::new();
        world.load_fixture_repos(&fixture);

        let manifest = fs::read_to_string(fixture.join("protofetch.toml"))
            .expect("read fixture protofetch.toml");
        let initial_lock = fs::read_to_string(fixture.join("protofetch.lock")).ok();
        let result = world.fetch_files(&manifest, initial_lock.as_deref(), lock_mode);

        let mut settings = Settings::clone_current();
        settings.set_snapshot_path(fixture.join("snapshots"));
        settings.set_prepend_module_to_snapshot(false);
        settings.set_omit_expression(true);
        settings.bind(|| {
            assert_snapshot!("output", result.snapshot_tree());
            assert_snapshot!("lockfile", result.snapshot_lockfile());
        });

        result
    }

    fn run_update(name: &str, lock_update_mode: LockUpdateMode) -> FetchResult {
        let fixture = Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("tests/e2e")
            .join(name);
        let mut world = Self::new();
        world.load_fixture_repos(&fixture);

        let lock_update_mode =
            resolve_lock_update_mode_labels(lock_update_mode, world.remotes.path(), &world.repos);

        let manifest = fs::read_to_string(fixture.join("protofetch.toml"))
            .expect("read fixture protofetch.toml");
        let initial_lock = fs::read_to_string(fixture.join("protofetch.lock")).ok();
        let result = world.update_files(&manifest, initial_lock.as_deref(), lock_update_mode);

        let mut settings = Settings::clone_current();
        settings.set_snapshot_path(fixture.join("snapshots"));
        settings.set_prepend_module_to_snapshot(false);
        settings.set_omit_expression(true);
        settings.bind(|| {
            assert_snapshot!("lockfile", result.snapshot_lockfile());
        });

        result
    }

    fn run_update_error(name: &str, lock_update_mode: LockUpdateMode) -> String {
        let fixture = Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("tests/e2e")
            .join(name);
        let mut world = Self::new();
        world.load_fixture_repos(&fixture);

        let lock_update_mode =
            resolve_lock_update_mode_labels(lock_update_mode, world.remotes.path(), &world.repos);

        let manifest = fs::read_to_string(fixture.join("protofetch.toml"))
            .expect("read fixture protofetch.toml");
        let initial_lock = fs::read_to_string(fixture.join("protofetch.lock")).ok();

        match world.update_files_result(&manifest, initial_lock.as_deref(), lock_update_mode) {
            Ok(_) => panic!("protofetch update should fail"),
            Err(error) => error.to_string(),
        }
    }

    fn load_fixture_repos(&mut self, fixture: &Path) {
        let mut commits = Vec::new();
        collect_fixture_commits(fixture, fixture, &mut commits);
        commits.sort_by(|a, b| {
            a.repo
                .cmp(&b.repo)
                .then_with(|| a.index.cmp(&b.index))
                .then_with(|| a.branch.cmp(&b.branch))
        });

        let mut created = BTreeSet::new();
        for commit in commits {
            let files = read_fixture_files(&commit.path)
                .into_iter()
                .map(|(path, content)| {
                    if path == "protofetch.toml" {
                        (path, prepare_manifest(&content, self.remotes.path()))
                    } else {
                        (path, content)
                    }
                })
                .collect::<Vec<_>>();
            let files = files
                .iter()
                .map(|(path, content)| (path.as_str(), content.as_str()))
                .collect::<Vec<_>>();

            if created.insert(commit.repo.clone()) {
                assert_eq!(
                    commit.index, 1,
                    "first fixture commit for {} must use commit index 1",
                    commit.repo
                );
                assert_eq!(
                    commit.branch, "main",
                    "first fixture commit for {} must be on main",
                    commit.repo
                );
                self.create_repo(&commit.repo, &files);
            } else {
                self.repo_mut(&commit.repo)
                    .add_commit(&commit.branch, &files);
            }
        }
    }

    fn repo_mut(&mut self, name: &str) -> &mut TestRepo {
        let path = self.remotes.path().join(name);
        self.repos
            .iter_mut()
            .find(|repo| repo.path == path)
            .expect("fixture repo exists")
    }

    /// Create a local git repository at `<remotes>/<name>` containing the
    /// given files and return its absolute path + commit info.
    ///
    /// `name` is a relative path such as `"repo1"` — it may include
    /// subdirectory components; the final directory becomes the repo root.
    ///
    /// `files` is a slice of `(relative-path-inside-repo, content)` pairs.
    pub fn create_repo(&mut self, name: &str, files: &[(&str, &str)]) -> &mut TestRepo {
        let repo_path = self.remotes.path().join(name);
        fs::create_dir_all(&repo_path).expect("create repo dir");

        let repo = Repository::init(&repo_path).expect("git init");

        // Write files, expanding <base> to the remotes root path.
        let base = self.remotes.path().to_string_lossy().replace('\\', "/");
        for (rel_path, content) in files {
            let abs = repo_path.join(rel_path);
            if let Some(parent) = abs.parent() {
                fs::create_dir_all(parent).expect("create file parent dir");
            }
            fs::write(&abs, content.replace("<base>", &base)).expect("write file");
        }

        // Stage all files.
        let mut index = repo.index().expect("repo index");
        index
            .add_all(["*"], IndexAddOption::DEFAULT, None)
            .expect("git add");
        index.write().expect("write index");
        let tree_oid = index.write_tree().expect("write tree");
        let tree = repo.find_tree(tree_oid).expect("find tree");

        // Commit.
        let sig = Signature::now("Test", "test@example.com").expect("signature");
        let commit_oid = repo
            .commit(
                Some("refs/heads/main"),
                &sig,
                &sig,
                "Initial commit",
                &tree,
                &[],
            )
            .expect("commit");

        self.repos.push(TestRepo {
            path: repo_path,
            remotes_path: self.remotes.path().to_path_buf(),
            commits: vec![("main".to_string(), commit_oid.to_string())],
        });
        self.repos.last_mut().unwrap()
    }

    fn fetch_files(
        &self,
        manifest: &str,
        initial_lock: Option<&str>,
        lock_mode: LockMode,
    ) -> FetchResult {
        fs::write(
            self.project.path().join("protofetch.toml"),
            resolve_labels(
                &prepare_manifest(manifest, self.remotes.path()),
                self.remotes.path(),
                &self.repos,
            ),
        )
        .expect("write protofetch.toml");

        if let Some(initial_lock) = initial_lock {
            fs::write(
                self.project.path().join("protofetch.lock"),
                resolve_labels(initial_lock, self.remotes.path(), &self.repos),
            )
            .expect("write initial protofetch.lock");
        }

        self.fetch_project(lock_mode)
    }

    fn update_files(
        &self,
        manifest: &str,
        initial_lock: Option<&str>,
        lock_update_mode: LockUpdateMode,
    ) -> FetchResult {
        self.update_files_result(manifest, initial_lock, lock_update_mode)
            .expect("protofetch update")
    }

    fn update_files_result(
        &self,
        manifest: &str,
        initial_lock: Option<&str>,
        lock_update_mode: LockUpdateMode,
    ) -> Result<FetchResult, Box<dyn Error>> {
        fs::write(
            self.project.path().join("protofetch.toml"),
            resolve_labels(
                &prepare_manifest(manifest, self.remotes.path()),
                self.remotes.path(),
                &self.repos,
            ),
        )
        .expect("write protofetch.toml");

        if let Some(initial_lock) = initial_lock {
            fs::write(
                self.project.path().join("protofetch.lock"),
                resolve_labels(initial_lock, self.remotes.path(), &self.repos),
            )
            .expect("write initial protofetch.lock");
        }

        self.protofetch().update(lock_update_mode)?;
        Ok(self.snapshot_project())
    }

    fn fetch_project(&self, lock_mode: LockMode) -> FetchResult {
        let pf = self.protofetch();

        pf.fetch(lock_mode).expect("protofetch fetch");
        self.snapshot_project()
    }

    fn protofetch(&self) -> Protofetch {
        Protofetch::builder()
            .root(self.project.path().to_path_buf())
            .cache_directory(self.cache.path().to_path_buf())
            .jobs(4)
            .copy_jobs(2)
            .try_build()
            .expect("build Protofetch")
    }

    fn snapshot_project(&self) -> FetchResult {
        let commits = self
            .repos
            .iter()
            .flat_map(|repo| repo.commits.iter().cloned())
            .collect::<Vec<_>>();
        let output_dir = self.project.path().join("proto_src");
        let lock_path = self.project.path().join("protofetch.lock");
        let remotes_path = self.remotes.path().to_path_buf();

        FetchResult {
            output_snapshot: snapshot_tree(&output_dir),
            lockfile_snapshot: snapshot_lockfile(&lock_path, &remotes_path, &commits),
        }
    }
}

pub fn run(name: &str) -> FetchResult {
    TestWorld::run(name, LockMode::Update)
}

pub fn run_update_selected(name: &str, dep: &str, precise: Option<&str>) -> FetchResult {
    TestWorld::run_update(name, selected_update_mode(dep, precise))
}

pub fn run_update_selected_error(name: &str, dep: &str, precise: &str) -> String {
    TestWorld::run_update_error(name, selected_update_mode(dep, Some(precise)))
}

fn selected_update_mode(dep: &str, precise: Option<&str>) -> LockUpdateMode {
    let updates = match precise {
        Some(precise) => vec![DependencyUpdate::Precise {
            name: dep.to_string(),
            commit_hash: precise.to_string(),
        }],
        None => vec![DependencyUpdate::Latest {
            name: dep.to_string(),
        }],
    };

    LockUpdateMode::ReconcileAndUpdate(updates)
}

pub fn run_locked(name: &str) -> FetchResult {
    TestWorld::run(name, LockMode::Locked)
}

fn prepare_manifest(manifest: &str, remotes_path: &Path) -> String {
    let mut manifest = manifest
        .parse::<toml::Table>()
        .expect("parse fixture manifest");
    let base = remotes_path.to_string_lossy().replace('\\', "/");

    let reserved = ["name", "description", "proto_out_dir"];
    for (key, value) in manifest.iter_mut() {
        if reserved.contains(&key.as_str()) {
            continue;
        }
        if let toml::Value::Table(dep) = value {
            dep.entry("protocol")
                .or_insert_with(|| toml::Value::String("file".to_string()));
            if let Some(toml::Value::String(url)) = dep.get_mut("url") {
                if url.starts_with("<base>/") {
                    *url = url.replacen("<base>", &base, 1);
                } else {
                    *url = format!("{base}/{url}");
                }
            }
        }
    }

    toml::to_string_pretty(&manifest).expect("serialize fixture manifest")
}

fn collect_fixture_commits(fixture: &Path, dir: &Path, commits: &mut Vec<FixtureCommit>) {
    let Ok(read_dir) = fs::read_dir(dir) else {
        return;
    };

    for entry in read_dir.filter_map(Result::ok) {
        let path = entry.path();
        if !path.is_dir() {
            continue;
        }
        if path.file_name().and_then(|name| name.to_str()) == Some("snapshots") {
            continue;
        }
        if let Some(index) = path
            .file_name()
            .and_then(|name| name.to_str())
            .and_then(|name| name.parse().ok())
        {
            let branch_path = path.parent().expect("commit has branch parent");
            let repo_path = branch_path.parent().expect("branch has repo parent");
            let branch = branch_path
                .file_name()
                .expect("branch name")
                .to_string_lossy()
                .into_owned();
            let repo = repo_path
                .strip_prefix(fixture)
                .expect("repo under fixture")
                .to_string_lossy()
                .replace('\\', "/");
            commits.push(FixtureCommit {
                repo,
                branch,
                index,
                path,
            });
        } else {
            collect_fixture_commits(fixture, &path, commits);
        }
    }
}

fn read_fixture_files(dir: &Path) -> Vec<(String, String)> {
    let mut entries = BTreeMap::new();
    collect_entries(dir, dir, &mut entries);
    entries.into_iter().collect()
}

/// Resolve snapshot labels back to real values so a labelled lock file can be
/// written to disk as input to protofetch.
///
/// - `<base>` → actual remotes path
/// - `<commit:branch:N>` → actual commit hash (using the same per-branch
///   counter as [`FetchResult::lockfile_snapshot`])
fn resolve_labels(content: &str, remotes_path: &Path, repos: &[TestRepo]) -> String {
    let base = remotes_path.to_string_lossy().replace('\\', "/");
    let mut result = content.replace("<base>", &base);

    let mut branch_counter: BTreeMap<&str, usize> = BTreeMap::new();
    for repo in repos {
        for (branch, hash) in &repo.commits {
            let n = branch_counter.entry(branch.as_str()).or_insert(0);
            *n += 1;
            let label = format!("<commit:{branch}:{n}>");
            result = result.replace(&label, hash);
        }
    }
    result
}

fn resolve_lock_update_mode_labels(
    lock_update_mode: LockUpdateMode,
    remotes_path: &Path,
    repos: &[TestRepo],
) -> LockUpdateMode {
    match lock_update_mode {
        LockUpdateMode::ReconcileAndUpdate(updates) => LockUpdateMode::ReconcileAndUpdate(
            updates
                .into_iter()
                .map(|update| match update {
                    DependencyUpdate::Latest { name } => DependencyUpdate::Latest { name },
                    DependencyUpdate::Precise {
                        name,
                        commit_hash: precise,
                    } => DependencyUpdate::Precise {
                        name,
                        commit_hash: resolve_labels(&precise, remotes_path, repos),
                    },
                })
                .collect(),
        ),
        lock_update_mode => lock_update_mode,
    }
}

/// Returned by [`TestWorld::fetch`]; provides access to all fetch outputs.
pub struct FetchResult {
    output_snapshot: String,
    lockfile_snapshot: String,
}

impl FetchResult {
    /// Walk the output directory and produce a single deterministic snapshot string.
    ///
    /// Every file under `output_dir` is rendered as:
    /// ```text
    /// === relative/path/to/file ===
    /// <file contents>
    /// ```
    /// Files are visited in sorted order so the snapshot is stable.
    pub fn snapshot_tree(&self) -> String {
        self.output_snapshot.clone()
    }

    /// Read the lock file and return a stable snapshot string.
    ///
    /// Two sources of non-determinism are redacted:
    /// - `url` values: the dynamic temp-dir prefix is replaced with `<base>`.
    /// - `commit_hash` / `revision` values: replaced with a deterministic label
    ///   derived from the commit's position across all repos in the world.
    ///
    /// Labels have the form `<commit:<branch>:<N>>` where N is a 1-based
    /// per-branch counter across all repos in creation order.  Unknown hashes
    /// are labelled `<commit:unknown>`.
    pub fn snapshot_lockfile(&self) -> String {
        self.lockfile_snapshot.clone()
    }
}

pub fn assert_output_contains(result: &FetchResult, paths: &[&str]) {
    let snapshot = result.snapshot_tree();
    for path in paths {
        assert!(
            snapshot.contains(&format!("=== {path} ===")),
            "expected output to contain {path}\n\n{snapshot}"
        );
    }
}

pub fn assert_output_excludes(result: &FetchResult, paths: &[&str]) {
    let snapshot = result.snapshot_tree();
    for path in paths {
        assert!(
            !snapshot.contains(&format!("=== {path} ===")),
            "expected output to exclude {path}\n\n{snapshot}"
        );
    }
}

fn snapshot_tree(output_dir: &Path) -> String {
    let mut entries: BTreeMap<String, String> = BTreeMap::new();
    collect_entries(output_dir, output_dir, &mut entries);

    entries
        .iter()
        .map(|(rel, content)| format!("=== {} ===\n{}", rel, content.trim_end_matches('\n')))
        .collect::<Vec<_>>()
        .join("\n\n")
        + "\n"
}

fn snapshot_lockfile(
    lock_path: &Path,
    remotes_path: &Path,
    commits: &[(String, String)],
) -> String {
    let mut hash_to_label: BTreeMap<&str, String> = BTreeMap::new();
    let mut branch_counter: BTreeMap<&str, usize> = BTreeMap::new();
    for (branch, hash) in commits {
        let n = branch_counter.entry(branch.as_str()).or_insert(0);
        *n += 1;
        hash_to_label.insert(hash.as_str(), format!("<commit:{branch}:{n}>"));
    }

    let content = fs::read_to_string(lock_path).expect("read protofetch.lock");
    let base = remotes_path.to_string_lossy().replace('\\', "/");
    content
        .lines()
        .map(|line| {
            for prefix in ["commit_hash = \"", "revision = \""] {
                if let Some(rest) = line.strip_prefix(prefix) {
                    let hash = rest.trim_end_matches('"');
                    let label = hash_to_label
                        .get(hash)
                        .cloned()
                        .unwrap_or_else(|| "<commit:unknown>".to_string());
                    let key = prefix.trim_end_matches(" = \"");
                    return format!("{key} = \"{label}\"");
                }
            }
            line.replace(base.as_str(), "<base>")
        })
        .collect::<Vec<_>>()
        .join("\n")
        + "\n"
}

fn collect_entries(base: &Path, dir: &Path, entries: &mut BTreeMap<String, String>) {
    let read_dir = match fs::read_dir(dir) {
        Ok(rd) => rd,
        Err(_) => return,
    };

    // Collect and sort for determinism.
    let mut children: Vec<PathBuf> = read_dir.filter_map(|e| e.ok().map(|e| e.path())).collect();
    children.sort();

    for path in children {
        if path.is_dir() {
            collect_entries(base, &path, entries);
        } else {
            let rel = path
                .strip_prefix(base)
                .expect("strip prefix")
                .to_string_lossy()
                .replace('\\', "/");
            let content = fs::read_to_string(&path).unwrap_or_else(|_| "<binary>".to_string());
            entries.insert(rel, content);
        }
    }
}