hatchzip 0.1.11

Extract huge archives in place: the archive shrinks as your files hatch, so you only need room for the output.
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
//! `extract --nested`: after the archives given, the archives among the files
//! they wrote are extracted too, by name and signature, one level deep.

mod common;

use std::fs;
use std::io::{Cursor, Write};
use std::path::Path;

use common::*;
use tempfile::TempDir;
use zip::ZipWriter;
use zip::write::SimpleFileOptions;

fn zip_bytes(files: &[(&str, &[u8])]) -> Vec<u8> {
    let mut zip = ZipWriter::new(Cursor::new(Vec::new()));
    for (name, data) in files {
        zip.start_file(*name, SimpleFileOptions::default()).unwrap();
        zip.write_all(data).unwrap();
    }
    zip.finish().unwrap().into_inner()
}

fn fixture(name: &str) -> Vec<u8> {
    fs::read(
        Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("tests/fixtures/nested")
            .join(name),
    )
    .unwrap()
}

fn extract_nested(archive: &Path, out: &Path, extra: &[&str]) -> std::process::Output {
    let mut args = vec![
        "extract",
        archive.to_str().unwrap(),
        "-o",
        out.to_str().unwrap(),
        "--nested",
        "--keep-free",
        "0",
        "--yes",
    ];
    args.extend_from_slice(extra);
    hatchzip(&args, &[])
}

#[test]
fn the_archives_inside_are_extracted_one_level() {
    let tmp = TempDir::new().unwrap();
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    // An archive the person already had in the destination, and one the
    // archive itself carries under an extension that is not an archive.
    let existing = zip_bytes(&[("user.txt", b"mine")]);
    fs::write(out.join("existing.zip"), &existing).unwrap();
    let mods = zip_bytes(&[("mod.class", b"x")]);
    let disguised = zip_bytes(&[("payload.txt", b"inside")]);

    let deeper = zip_bytes(&[("deeper.txt", b"three")]);
    let first = zip_bytes(&[("first.txt", b"one"), ("deeper.zip", &deeper)]);
    let mut files = Files::new();
    files.insert("second.txt".into(), b"two".to_vec());
    let second = targz_of(tmp.path(), "second.tar.gz", &files);
    let second = fs::read(second).unwrap();
    let mut mods_files = Files::new();
    mods_files.insert("mods/inner.txt".into(), b"zstd".to_vec());
    let nested_zst = tarzst_of(tmp.path(), "mods.tar.zst", &mods_files);
    let nested_zst = fs::read(nested_zst).unwrap();
    let outer = zip_bytes(&[
        ("first.zip", &first),
        ("second.tar.gz", &second),
        ("third.tar.bz2", &fixture("third.tar.bz2")),
        ("mods.tar.zst", &nested_zst),
        ("fake.tar.xz", &fixture("fake.tar.xz")),
        ("notes.zip", b"not an archive at all"),
        ("patch.dat", &disguised),
        ("mod.jar", &mods),
    ]);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer).unwrap();

    assert_ok(&extract_nested(&archive, &out, &[]));
    assert!(!archive.exists(), "the outer archive is removed");
    assert_eq!(fs::read(out.join("first/first.txt")).unwrap(), b"one");
    assert_eq!(fs::read(out.join("second/second.txt")).unwrap(), b"two");
    assert_eq!(
        fs::read(out.join("third/third.txt")).unwrap(),
        b"three-bz\n"
    );
    assert_eq!(fs::read(out.join("mods/mods/inner.txt")).unwrap(), b"zstd");
    assert!(
        !out.join("first.zip").exists()
            && !out.join("second.tar.gz").exists()
            && !out.join("third.tar.bz2").exists()
            && !out.join("mods.tar.zst").exists(),
        "the nested archives are removed in place"
    );
    assert!(
        out.join("notes.zip").exists() && out.join("fake.tar.xz").exists(),
        "a name alone is not enough"
    );
    assert!(
        out.join("patch.dat").exists() && out.join("mod.jar").exists(),
        "only archive extensions are considered, not every ZIP"
    );
    assert!(
        out.join("existing.zip").exists() && !out.join("existing").exists(),
        "only what this run wrote is a candidate"
    );
    assert_eq!(
        fs::read(out.join("existing.zip")).unwrap(),
        existing,
        "the file that was already there is untouched"
    );
    assert!(
        out.join("first/deeper.zip").exists() && !out.join("first/deeper").exists(),
        "one level only"
    );
}

#[test]
fn without_the_flag_the_archives_stay_where_they_landed() {
    let tmp = TempDir::new().unwrap();
    let inner = zip_bytes(&[("first.txt", b"one")]);
    let outer = zip_bytes(&[("first.zip", &inner)]);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer).unwrap();
    let out = tmp.path().join("out");

    let run = hatchzip(
        &[
            "extract",
            archive.to_str().unwrap(),
            "-o",
            out.to_str().unwrap(),
            "--keep-free",
            "0",
            "--yes",
        ],
        &[],
    );
    assert_ok(&run);
    assert!(out.join("first.zip").exists());
    assert!(!out.join("first").exists());
}

/// With `--skip-existing`, the file at a nested archive's path is the
/// person's, not the one the run wrote, so it is not a candidate.
#[test]
fn a_skipped_file_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    let user = zip_bytes(&[("user.txt", b"mine")]);
    fs::write(out.join("first.zip"), &user).unwrap();

    let inner = zip_bytes(&[("first.txt", b"one")]);
    let outer = zip_bytes(&[("first.zip", &inner)]);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer).unwrap();

    let run = hatchzip(
        &[
            "extract",
            archive.to_str().unwrap(),
            "-o",
            out.to_str().unwrap(),
            "--nested",
            "--skip-existing",
            "--keep-free",
            "0",
            "--yes",
        ],
        &[],
    );
    assert_ok(&run);
    assert!(!out.join("first").exists(), "nothing was extracted");
    assert_eq!(fs::read(out.join("first.zip")).unwrap(), user);
}

/// A `.zip` this run wrote next to the person's own `.z01` names a split set
/// whose first part is theirs. Extracting it in place would remove their
/// file, so it is not offered.
#[test]
fn a_set_whose_first_part_was_already_there_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    let theirs = b"the first part of someone else's set".to_vec();
    fs::write(out.join("set.z01"), &theirs).unwrap();

    let inner = zip_bytes(&[("inside.txt", b"one")]);
    let outer = zip_bytes(&[("set.zip", &inner)]);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer).unwrap();

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    assert!(
        String::from_utf8_lossy(&run.stdout).contains("No archives among the extracted files."),
        "{}",
        String::from_utf8_lossy(&run.stdout)
    );
    assert_eq!(fs::read(out.join("set.z01")).unwrap(), theirs);
    assert_eq!(fs::read(out.join("set.zip")).unwrap(), inner);
}

/// An archive inside that lands next to progress files of its name would be
/// resumed from what they say, so it is not offered, and they stay as they
/// were. An archive can't bring them itself; these were in the folder.
#[test]
fn an_archive_inside_with_progress_files_next_to_it_is_not_extracted() {
    for side in [
        "inner.zip.hatchzip",
        "inner.zip.hatchzip-tail",
        "inner.zip.hatchzip-folders",
    ] {
        let tmp = TempDir::new().unwrap();
        let out = tmp.path().join("out");
        fs::create_dir_all(&out).unwrap();
        fs::write(out.join(side), b"{}").unwrap();

        let inner = zip_bytes(&[("inside.txt", b"one")]);
        let outer = zip_bytes(&[("inner.zip", &inner)]);
        let archive = tmp.path().join("outer.zip");
        fs::write(&archive, outer).unwrap();

        let run = extract_nested(&archive, &out, &[]);
        assert_ok(&run);
        assert!(
            String::from_utf8_lossy(&run.stdout).contains("No archives among the extracted files."),
            "{side}: {}",
            String::from_utf8_lossy(&run.stdout)
        );
        assert_eq!(fs::read(out.join("inner.zip")).unwrap(), inner, "{side}");
        assert!(!out.join("inner").exists(), "{side}");
        assert_eq!(fs::read(out.join(side)).unwrap(), b"{}", "{side}");
    }
}

fn split_files() -> Files {
    let mut files = Files::new();
    files.insert("data/big.bin".into(), noise(60_000, 5));
    files.insert("readme.txt".into(), b"split inside".to_vec());
    files
}

/// `files` as the native split ZIP `set.z01`, `set.z02`, ..., `set.zip`,
/// named and in order, with enough segments that one in the middle can go
/// missing and the set still has a `.z01` and a `.zip`.
fn split_set(files: &Files) -> Vec<(String, Vec<u8>)> {
    let tmp = TempDir::new().unwrap();
    let whole = fs::read(zip_of(tmp.path(), "whole.zip", files)).unwrap();
    let s = Split {
        size: 10_000,
        ..Split::default()
    };
    let segments = split_zip_segments(&whole, &s);
    let n = segments.len();
    assert!(n >= 4, "only {n} segments");
    segments
        .into_iter()
        .enumerate()
        .map(|(i, bytes)| {
            let name = split_zip_name(Path::new(""), "set", i, n, false);
            (name.to_str().unwrap().to_string(), bytes)
        })
        .collect()
}

fn outer_of(parts: &[&(String, Vec<u8>)]) -> Vec<u8> {
    let entries: Vec<(&str, &[u8])> = parts
        .iter()
        .map(|(name, bytes)| (name.as_str(), bytes.as_slice()))
        .collect();
    zip_bytes(&entries)
}

/// Every one of `parts` is in `out`, as it was written.
fn assert_parts(out: &Path, parts: &[&(String, Vec<u8>)]) {
    for (name, bytes) in parts {
        assert_eq!(&fs::read(out.join(name)).unwrap(), bytes, "{name}");
    }
}

fn stdout_of(run: &std::process::Output) -> String {
    String::from_utf8_lossy(&run.stdout).into_owned()
}

/// A native split ZIP the run wrote whole is one archive, found by its
/// `.z01`, whose split marker is no ZIP signature, and extracted as a set
/// in place: every segment is gone afterwards.
#[test]
fn a_split_zip_inside_is_extracted_once_as_a_set() {
    let tmp = TempDir::new().unwrap();
    let files = split_files();
    let parts = split_set(&files);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&parts.iter().collect::<Vec<_>>())).unwrap();
    let out = tmp.path().join("out");

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    let stdout = stdout_of(&run);
    assert!(
        stdout.contains("Nested archive:") && stdout.contains("The nested archive was extracted."),
        "the set is offered once: {stdout}"
    );
    assert_tree(&out.join("set"), &files);
    for (name, _) in &parts {
        assert!(!out.join(name).exists(), "{name} is left");
    }
}

/// The rest of a set next to the person's own `.z01` is not the run's set:
/// extracting it in place would remove their file.
#[test]
fn a_split_zip_whose_first_segment_was_already_there_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let parts = split_set(&split_files());
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    fs::write(out.join(&parts[0].0), &parts[0].1).unwrap();
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&parts[1..].iter().collect::<Vec<_>>())).unwrap();

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    assert!(
        stdout_of(&run).contains("No archives among the extracted files."),
        "{}",
        stdout_of(&run)
    );
    assert_parts(&out, &parts.iter().collect::<Vec<_>>());
}

/// With `--skip-existing`, a segment the person had stays in place of the
/// run's copy. It would be removed with the set, so the set is not offered.
#[test]
fn a_split_zip_with_a_skipped_segment_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let parts = split_set(&split_files());
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    fs::write(out.join(&parts[1].0), &parts[1].1).unwrap();
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&parts.iter().collect::<Vec<_>>())).unwrap();

    let run = extract_nested(&archive, &out, &["--skip-existing"]);
    assert_ok(&run);
    assert!(
        stdout_of(&run).contains("No archives among the extracted files."),
        "{}",
        stdout_of(&run)
    );
    assert_parts(&out, &parts.iter().collect::<Vec<_>>());
    assert!(!out.join("set").exists(), "nothing was extracted");
}

/// `.z01`, `.z03`, ... and `.zip` without the `.z02` are a set with a hole,
/// so it is not offered.
#[test]
fn a_split_zip_missing_a_middle_segment_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let parts = split_set(&split_files());
    let left: Vec<_> = parts
        .iter()
        .enumerate()
        .filter(|(i, _)| *i != 1)
        .map(|(_, p)| p)
        .collect();
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&left)).unwrap();
    let out = tmp.path().join("out");

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    assert!(
        stdout_of(&run).contains("No archives among the extracted files."),
        "{}",
        stdout_of(&run)
    );
    assert_parts(&out, &left);
    assert!(!out.join(&parts[1].0).exists());
    assert!(!out.join("set").exists(), "nothing was extracted");
}

/// A `.z01` and a `.zip` look like a whole set by name, but the index says
/// there are more segments. Opening it finds that, so it is not offered,
/// and no progress file or folder is left behind.
#[test]
fn a_split_zip_missing_segments_its_index_names_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let parts = split_set(&split_files());
    let ends = [&parts[0], &parts[parts.len() - 1]];
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&ends)).unwrap();
    let out = tmp.path().join("out");

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    assert!(
        stdout_of(&run).contains("No archives among the extracted files."),
        "{}",
        stdout_of(&run)
    );
    assert_parts(&out, &ends);
    for left in [
        "set.z01.hatchzip",
        "set.z01.hatchzip-tail",
        "set.z01.hatchzip-folders",
        "set.zip.hatchzip",
        "set",
    ] {
        assert!(!out.join(left).exists(), "{left} is left");
    }
}

/// The person's own `.z02` between the run's `.z01` and `.zip` makes the
/// set partly theirs, so it is not offered.
#[test]
fn a_split_zip_with_the_persons_middle_segment_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let parts = split_set(&split_files());
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    fs::write(out.join(&parts[1].0), &parts[1].1).unwrap();
    let theirs: Vec<_> = parts
        .iter()
        .enumerate()
        .filter(|(i, _)| *i != 1)
        .map(|(_, p)| p)
        .collect();
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&theirs)).unwrap();

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    assert!(
        stdout_of(&run).contains("No archives among the extracted files."),
        "{}",
        stdout_of(&run)
    );
    assert_parts(&out, &parts.iter().collect::<Vec<_>>());
    assert!(!out.join("set").exists(), "nothing was extracted");
}

/// A split set or a single archive with progress files next to it would
/// resume from what they say, so neither is offered, and nothing changes. An
/// archive can't carry such files itself (it is refused), so they are already
/// in the destination here.
#[test]
fn an_archive_with_progress_files_next_to_it_is_not_extracted() {
    let tmp = TempDir::new().unwrap();
    let parts = split_set(&split_files());
    let out = tmp.path().join("out");
    fs::create_dir_all(&out).unwrap();
    let journal = (String::from("set.z01.hatchzip"), b"{}".to_vec());
    let plain_journal = (String::from("foo.zip.hatchzip"), b"{}".to_vec());
    for (name, bytes) in [&journal, &plain_journal] {
        fs::write(out.join(name), bytes).unwrap();
    }
    let plain = (String::from("foo.zip"), zip_bytes(&[("foo.txt", b"foo")]));
    let mut all: Vec<_> = parts.iter().collect();
    all.push(&plain);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&all)).unwrap();

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    assert!(
        stdout_of(&run).contains("No archives among the extracted files."),
        "{}",
        stdout_of(&run)
    );
    assert_parts(&out, &all);
    assert_parts(&out, &[&journal, &plain_journal]);
    assert!(!out.join("set").exists() && !out.join("foo").exists());
}

/// A RAR set inside counts once, by its first volume, even when a later
/// volume comes first in the archive.
#[cfg(feature = "rar")]
#[test]
fn a_rar_set_inside_is_extracted_once_from_its_first_volume() {
    let tmp = TempDir::new().unwrap();
    let from = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/rar/rar5");
    let mut volumes: Vec<(String, Vec<u8>)> = fs::read_dir(&from)
        .unwrap()
        .map(|e| {
            let e = e.unwrap();
            let name = e.file_name().to_string_lossy().into_owned();
            (name, fs::read(e.path()).unwrap())
        })
        .collect();
    volumes.sort();
    assert!(volumes.len() >= 3 && volumes[1].0 == "set.part2.rar");
    // `set.part2.rar` first, then `set.part1.rar` and the rest.
    volumes.swap(0, 1);
    let archive = tmp.path().join("outer.zip");
    fs::write(&archive, outer_of(&volumes.iter().collect::<Vec<_>>())).unwrap();
    let out = tmp.path().join("out");

    let run = extract_nested(&archive, &out, &[]);
    assert_ok(&run);
    let stdout = stdout_of(&run);
    assert!(
        stdout.contains("Nested archive:") && stdout.contains("set.part1.rar"),
        "the set is offered once, by its first volume: {stdout}"
    );
    assert_eq!(
        fs::read(out.join("set/game/d.pak")).unwrap(),
        noise(6_000, 9)
    );
    assert_eq!(
        fs::read(out.join("set/game/a.pak")).unwrap(),
        noise(30_000, 1)
    );
    for (name, _) in &volumes {
        assert!(!out.join(name).exists(), "{name} is left");
    }
}
/// A link inside the output can point anywhere; the scan must not follow it.
#[cfg(unix)]
#[test]
fn a_link_is_not_followed_or_extracted() {
    let tmp = TempDir::new().unwrap();
    let outside = tmp.path().join("outside.zip");
    fs::write(&outside, zip_bytes(&[("x.txt", b"x")])).unwrap();

    let mut tar = tar::Builder::new(Vec::new());
    let mut header = tar::Header::new_gnu();
    header.set_entry_type(tar::EntryType::Symlink);
    header.set_size(0);
    header.set_mode(0o777);
    tar.append_link(&mut header, "link.zip", "../outside.zip")
        .unwrap();
    let archive = tmp.path().join("outer.tar");
    fs::write(&archive, tar.into_inner().unwrap()).unwrap();
    let out = tmp.path().join("out");

    assert_ok(&extract_nested(&archive, &out, &[]));
    let link = out.join("link.zip");
    assert!(
        fs::symlink_metadata(&link)
            .unwrap()
            .file_type()
            .is_symlink(),
        "the link survives"
    );
    assert!(outside.exists(), "what it points at is untouched");
    assert!(!out.join("link").exists(), "nothing was extracted");
}

/// The scan must not follow a Windows link either. An archive cannot carry
/// one, so the link is left in the output between two runs, the way a user
/// would. Windows makes links only with Developer Mode on or as admin; the
/// test steps aside where the machine cannot.
#[cfg(windows)]
#[test]
fn a_windows_link_is_not_followed_or_extracted() {
    let tmp = TempDir::new().unwrap();
    let outside = tmp.path().join("outside.zip");
    fs::write(&outside, zip_bytes(&[("x.txt", b"x")])).unwrap();

    let first = zip_bytes(&[("holder.zip", &zip_bytes(&[("y.txt", b"y")]))]);
    let archive = tmp.path().join("outer1.zip");
    fs::write(&archive, first).unwrap();
    let out = tmp.path().join("out");
    assert_ok(&extract_nested(&archive, &out, &[]));

    if std::os::windows::fs::symlink_file(&outside, out.join("link.zip")).is_err() {
        return;
    }

    let second = zip_bytes(&[("holder2.zip", &zip_bytes(&[("z.txt", b"z")]))]);
    let archive = tmp.path().join("outer2.zip");
    fs::write(&archive, second).unwrap();
    assert_ok(&extract_nested(&archive, &out, &[]));

    let link = out.join("link.zip");
    assert!(
        fs::symlink_metadata(&link)
            .unwrap()
            .file_type()
            .is_symlink(),
        "the link survives"
    );
    assert!(outside.exists(), "what it points at is untouched");
    assert!(!out.join("link").exists(), "nothing was extracted");
}