Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package fsutil
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -54,3 +56,16 @@ func TestStat(t *testing.T) {
st.ModTime = 0
assert.Equal(t, &types.Stat{Path: "sock", Mode: 0755 /* ModeSocket not set */}, st)
}

func TestStat_SkipAppleXattrs(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("skipping test that requires darwin")
}

st, err := Stat("Dockerfile")
assert.NoError(t, err)

for key := range st.Xattrs {
assert.False(t, strings.HasPrefix(key, "com.apple."))
}
}
22 changes: 19 additions & 3 deletions stat_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ package fsutil

import (
"os"
"strings"
"syscall"

"github.com/containerd/continuity/sysx"
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil/types"
)

const xattrApplePrefix = "com.apple."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an extensible (e.g. map or slice) list of attributes to skip? I know there's been some back-and-forth on some of these (incompatible attributes, and/or some attributes that must be omitted (I recall SELinux labels, but they're probably excluded already), others that should be kept).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just do that later. I don't think I see a strong reason to add a map or slice considering that would probably end up resulting in some data allocated in a global section of memory for what is currently one attribute. This constant should just end up getting inlined without any performance cost.

If the list were longer or more involved I think it might be easier to have a map or slice but I think it's likely over-optimizing in the current code.


func loadXattr(origpath string, stat *types.Stat) error {
xattrs, err := sysx.LListxattr(origpath)
if err != nil {
Expand All @@ -23,16 +26,29 @@ func loadXattr(origpath string, stat *types.Stat) error {
if len(xattrs) > 0 {
m := make(map[string][]byte)
for _, key := range xattrs {
v, err := sysx.LGetxattr(origpath, key)
if err == nil {
if skipXattr(key) {
continue
}

if v, err := sysx.LGetxattr(origpath, key); err == nil {
m[key] = v
}
}
stat.Xattrs = m

if len(m) > 0 {
stat.Xattrs = m
}
}
return nil
}

func skipXattr(key string) bool {
if strings.HasPrefix(key, xattrApplePrefix) {
return true
}
return false
}

func setUnixOpt(fi os.FileInfo, stat *types.Stat, path string, seenFiles map[uint64]string) {
s := fi.Sys().(*syscall.Stat_t)

Expand Down