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
//! Pure-Rust tar + gzip — the CLI packs and unpacks the per-binary
//! tarball without shelling out to a host `tar` (no `tar` dependency
//! for `cargo athena build`/`publish`/`emulate`).
//!
//! **Argo's `unpack` quirk (proven from Argo v4.0.5 source,
//! `workflow/executor/executor.go:1177-1218`):** the executor extracts
//! the input tarball into a temp dir, then:
//!
//! * if exactly **one** top-level entry → `os.Rename(entry, destPath)`
//! (so `dest` BECOMES the entry — a directory iff the entry was a
//! directory, a file iff the entry was a file!);
//! * else → `os.Rename(tmpDir, destPath)` (so `dest` is a directory
//! whose contents are the tarball's top-level entries).
//!
//! That single-entry rename is **the** footgun: if we packed the binary
//! directly at the top level, a single-target tarball would have Argo
//! rename `app-<triple>` to `/athena/bin` → `/athena/bin` is a FILE
//! (the binary) rather than a directory containing it, and the
//! bootstrap's `/athena/bin/app-<triple>` path breaks.
//!
//! **The fix this module enforces by construction:** every tarball
//! [`create`] writes packs entries under a single top-level **`bin/`**
//! subdirectory. After Argo's unpack, the `bin/` subdir is renamed to
//! `/athena/bin` (the artifact path), so `/athena/bin/app-<triple>`
//! resolves correctly for *both* single- and multi-arch tarballs.
//!
//! The [`extract_argo_compat`] function mirrors Argo's exact unpack
//! semantics on the host so `cargo athena container emulate` stays
//! zero-drift with the real in-pod path.
use File;
use io;
use Path;
/// Top-level directory name inside every tarball we produce. Argo's
/// single-entry rename will rename THIS directory to the artifact
/// `path`, guaranteeing `/athena/bin` is a directory (not a file) in
/// both single- and multi-arch cases.
const WRAP_DIR: &str = "bin";
/// Pack `(src_path, archive_name)` entries into a gzipped tar at `out`.
/// Each entry is written under [`WRAP_DIR`] (so the final archive name
/// is `bin/<archive_name>`); see the module doc for why.
///
/// File mode is taken from the source; we set 0o755 on the wrapping
/// directory header so the extracted dir is traversable. The compression
/// level is the default (6) — small win for a few MB of compressed
/// binaries; not worth tuning.
/// Extract a gzipped tarball into `dst`, matching Argo's
/// `executor.unpack` semantics 1:1 (proven from source — see module
/// doc). `dst` is created (or replaced) as either a file or a
/// directory depending on the tarball's top-level layout, exactly as
/// Argo's executor init container would do.
///
/// Used by `cargo athena container emulate` to pre-stage `/athena/bin`
/// on the host bind-mount — zero-drift with the in-pod path.