Skip to content

Commit 2c009be

Browse files
committed
fix(unpack): support unpacking readonly folders
layer unpacking preserves the original filemode. If the layer contains a readonly director, this would cause unpack to fail, because the dir on disk would not be writeable, and it's children would fail to write. this change makes all unpacked files owner-writable, which has some implications for how unpacked files should be used, but for purposes within opm this will not be an issue.
1 parent 18b8ef3 commit 2c009be

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/image/containerdregistry/registry.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"context"
77
"encoding/json"
88
"fmt"
9+
"io"
10+
"io/ioutil"
11+
"os"
12+
913
"github.com/containerd/containerd/archive"
1014
"github.com/containerd/containerd/archive/compression"
1115
"github.com/containerd/containerd/errdefs"
@@ -15,9 +19,6 @@ import (
1519
"github.com/containerd/containerd/remotes"
1620
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1721
"github.com/sirupsen/logrus"
18-
"io"
19-
"io/ioutil"
20-
"os"
2122

2223
"github.com/operator-framework/operator-registry/pkg/image"
2324
)
@@ -195,5 +196,11 @@ func adjustPerms(h *tar.Header) (bool, error) {
195196
h.Uid = os.Getuid()
196197
h.Gid = os.Getgid()
197198

199+
// Make all unpacked files owner-writable
200+
// This prevents errors when unpacking a layer that contains a read-only folder (if permissions are preserved,
201+
// file contents cannot be unpacked into the unpacked read-only folder).
202+
// This also means that "unpacked" layers cannot be "repacked" without potential information loss
203+
h.Mode |= 0200
204+
198205
return true, nil
199206
}

0 commit comments

Comments
 (0)