copier.unwrapError(): update for Go 1.16

Since we started calling into the standard library's io/fs package
directly, we effectively made Go 1.16 our minimum Go version, so we
don't need to keep the workaround for compiling with Go 1.12.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2022-04-26 18:02:35 -04:00
parent 4eb83eabb2
commit eb38649a25
5 changed files with 24 additions and 32 deletions

View File

@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"encoding/json"
stderrors "errors"
"fmt"
"io"
"io/fs"
@ -1907,3 +1908,15 @@ func copierHandlerRemove(req request) *response {
}
return &response{Error: "", Remove: removeResponse{}}
}
func unwrapError(err error) error {
e := errors.Cause(err)
for e != nil {
err = e
e = stderrors.Unwrap(err)
if e == err {
break
}
}
return err
}

View File

@ -1,11 +0,0 @@
// +build !go113
package copier
import (
"github.com/pkg/errors"
)
func unwrapError(err error) error {
return errors.Cause(err)
}

View File

@ -1,18 +0,0 @@
// +build go113
package copier
import (
stderror "errors"
"github.com/pkg/errors"
)
func unwrapError(err error) error {
e := errors.Cause(err)
for e != nil {
err = e
e = errors.Unwrap(err)
}
return err
}

View File

@ -16,7 +16,9 @@ const (
)
var (
relevantAttributes = []string{"security.capability", "security.ima", "user.*"} // the attributes that we preserve - we discard others
relevantAttributes = []string{"security.capability", "security.ima", "user.*"} // the attributes that we preserve - we discard others
initialXattrListSize = 64 * 1024
initialXattrValueSize = 64 * 1024
)
// isRelevantXattr checks if "attribute" matches one of the attribute patterns
@ -35,7 +37,7 @@ func isRelevantXattr(attribute string) bool {
// Lgetxattrs returns a map of the relevant extended attributes set on the given file.
func Lgetxattrs(path string) (map[string]string, error) {
maxSize := 64 * 1024 * 1024
listSize := 64 * 1024
listSize := initialXattrListSize
var list []byte
for listSize < maxSize {
list = make([]byte, listSize)
@ -61,7 +63,7 @@ func Lgetxattrs(path string) (map[string]string, error) {
m := make(map[string]string)
for _, attribute := range strings.Split(string(list), string('\000')) {
if isRelevantXattr(attribute) {
attributeSize := 64 * 1024
attributeSize := initialXattrValueSize
var attributeValue []byte
for attributeSize < maxSize {
attributeValue = make([]byte, attributeSize)

View File

@ -10,6 +10,12 @@ import (
"github.com/stretchr/testify/assert"
)
func init() {
// exercise the ERANGE-handling logic
initialXattrListSize = 1
initialXattrValueSize = 1
}
func TestXattrs(t *testing.T) {
if !xattrsSupported {
t.Skipf("xattrs are not supported on this platform, skipping")