Add NoSameOwner option when unpacking tars
When unpacking a TAR archive, containerd preserves file's owner: https://github.com/containerd/containerd/blob/main/archive/tar.go#L384 In some cases this behavior is not desired. In current implementation we avoid `Lchown` on Windows. Another case when this should be skipped is when using native snapshotter on darwin and running as non-root user. This PR extracts a generic option - `WithNoSameOwner` (same as `tar --no-same-owner`) to skip `Lchown` when its not required. Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
13
install.go
13
install.go
@@ -70,7 +70,8 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
|
||||
ra.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) {
|
||||
|
||||
filter := archive.WithFilter(func(hdr *tar.Header) (bool, error) {
|
||||
d := filepath.Dir(hdr.Name)
|
||||
result := d == binDir
|
||||
|
||||
@@ -87,7 +88,15 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
})); err != nil {
|
||||
})
|
||||
|
||||
opts := []archive.ApplyOpt{filter}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
opts = append(opts, archive.WithNoSameOwner())
|
||||
}
|
||||
|
||||
if _, err := archive.Apply(ctx, path, r, opts...); err != nil {
|
||||
r.Close()
|
||||
ra.Close()
|
||||
return err
|
||||
|
Reference in New Issue
Block a user