diff --git a/copier/copier.go b/copier/copier.go index d9f531acc..d5e96f9fe 100644 --- a/copier/copier.go +++ b/copier/copier.go @@ -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 +} diff --git a/copier/unwrap_112.go b/copier/unwrap_112.go deleted file mode 100644 index ebbad08b9..000000000 --- a/copier/unwrap_112.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !go113 - -package copier - -import ( - "github.com/pkg/errors" -) - -func unwrapError(err error) error { - return errors.Cause(err) -} diff --git a/copier/unwrap_113.go b/copier/unwrap_113.go deleted file mode 100644 index cd0d0fb68..000000000 --- a/copier/unwrap_113.go +++ /dev/null @@ -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 -} diff --git a/copier/xattrs.go b/copier/xattrs.go index c757adcc8..aef0f4403 100644 --- a/copier/xattrs.go +++ b/copier/xattrs.go @@ -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) diff --git a/copier/xattrs_test.go b/copier/xattrs_test.go index 86b21452b..f42ce9b15 100644 --- a/copier/xattrs_test.go +++ b/copier/xattrs_test.go @@ -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")