Skip to content

Commit 6f83d33

Browse files
committed
oci: preserve dir mode when extracting tar layers
OCI push/pull/diff is currently not "round-trip" safe, because the tar extraction function hardcodes 0o750 for directories
1 parent 357bbcc commit 6f83d33

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

oci/diff_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,40 @@ func TestClient_Diff(t *testing.T) {
6363
g.Expect(err).To(HaveOccurred())
6464
g.Expect(err).To(MatchError("the remote artifact contents differs from the local one"))
6565
}
66+
67+
func TestClient_PushPullDiff_RoundTrip(t *testing.T) {
68+
g := NewWithT(t)
69+
ctx := context.Background()
70+
c := NewClient(DefaultOptions())
71+
tag := "v0.0.1"
72+
repo := "test-push" + randStringRunes(5)
73+
74+
url := fmt.Sprintf("%s/%s:%s", dockerReg, repo, tag)
75+
metadata := Metadata{
76+
Source: "github.com/fluxcd/flux2",
77+
Revision: "rev",
78+
}
79+
80+
testDir := "testdata/artifact"
81+
_, err := c.Push(ctx, url, testDir, WithPushMetadata(metadata))
82+
g.Expect(err).ToNot(HaveOccurred())
83+
84+
err = c.Diff(ctx, url, testDir, nil)
85+
g.Expect(err).ToNot(HaveOccurred())
86+
87+
testDirStat, err := os.Stat(testDir)
88+
g.Expect(err).ToNot(HaveOccurred())
89+
90+
tmpPullDir, err := os.MkdirTemp("", "oci")
91+
g.Expect(err).ToNot(HaveOccurred())
92+
defer os.RemoveAll(tmpPullDir)
93+
94+
err = os.Chmod(tmpPullDir, testDirStat.Mode())
95+
g.Expect(err).ToNot(HaveOccurred())
96+
97+
_, err = c.Pull(ctx, url, tmpPullDir)
98+
g.Expect(err).ToNot(HaveOccurred())
99+
100+
err = c.Diff(ctx, url, tmpPullDir, nil)
101+
g.Expect(err).ToNot(HaveOccurred())
102+
}

tar/tar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func Untar(r io.Reader, dir string, inOpts ...TarOption) (err error) {
177177
}
178178
}
179179
case mode.IsDir():
180-
if err := os.MkdirAll(abs, 0o750); err != nil {
180+
if err := os.MkdirAll(abs, mode); err != nil {
181181
return err
182182
}
183183
madeDir[abs] = true

0 commit comments

Comments
 (0)