Skip to content

Commit

Permalink
vfs:ignore all unsupported xattr flags on the MacOS platform
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Nov 28, 2024
1 parent 4bdf11a commit 993d518
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
8 changes: 6 additions & 2 deletions pkg/meta/utils_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const (
XattrCreateOrReplace = 0
XattrCreate = sys.XATTR_CREATE
XattrReplace = sys.XATTR_REPLACE
XattrNoSecurity = sys.XATTR_NOSECURITY
XattrNoFollow = sys.XATTR_NOFOLLOW

//not supported
XattrNoSecurity = sys.XATTR_NOSECURITY
XATTR_NODEFAULT = sys.XATTR_NODEFAULT
XattrNoFollow = sys.XATTR_NOFOLLOW
XATTR_SHOWCOMPRESSION = sys.XATTR_SHOWCOMPRESSION
)
12 changes: 7 additions & 5 deletions pkg/meta/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const (
)

const (
XattrCreateOrReplace = 0
XattrCreate = sys.XATTR_CREATE
XattrReplace = sys.XATTR_REPLACE
XattrNoSecurity = 8
XattrNoFollow = 16
XattrCreateOrReplace = 0
XattrCreate = sys.XATTR_CREATE
XattrReplace = sys.XATTR_REPLACE
XattrNoSecurity = 8
XATTR_NODEFAULT = 10
XattrNoFollow = 16
XATTR_SHOWCOMPRESSION = 20
)
12 changes: 7 additions & 5 deletions pkg/meta/utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const (
)

const (
XattrCreateOrReplace = 0
XattrCreate = 1
XattrReplace = 2
XattrNoSecurity = 8
XattrNoFollow = 16
XattrCreateOrReplace = 0
XattrCreate = 1
XattrReplace = 2
XattrNoSecurity = 8
XATTR_NODEFAULT = 10
XattrNoFollow = 16
XATTR_SHOWCOMPRESSION = 20
)
11 changes: 5 additions & 6 deletions pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ const (
xattrMaxSize = 65536
)

var macUnSupportFlags = meta.XattrNoSecurity | meta.XATTR_NODEFAULT | meta.XattrNoFollow | meta.XATTR_SHOWCOMPRESSION

func (v *VFS) SetXattr(ctx Context, ino Ino, name string, value []byte, flags uint32) (err syscall.Errno) {
defer func() { logit(ctx, "setxattr", err, "(%d,%s,%d,%d)", ino, name, len(value), flags) }()
if IsSpecialNode(ino) {
Expand Down Expand Up @@ -1078,12 +1080,9 @@ func (v *VFS) SetXattr(ctx Context, ino Ino, name string, value []byte, flags ui
err = v.Meta.SetFacl(ctx, ino, aclType, rule)
v.invalidateAttr(ino)
} else {
// ignore NoSecurity flag
if runtime.GOOS == "darwin" && (flags&meta.XattrNoSecurity) != 0 {
flags &= ^uint32(meta.XattrNoSecurity)
}
if runtime.GOOS == "darwin" && (flags&meta.XattrNoFollow) != 0 {
flags &= ^uint32(meta.XattrNoFollow)
// ignore unsupported flags
if runtime.GOOS == "darwin" && (flags&uint32(macUnSupportFlags) != 0) {
flags &= ^uint32(macUnSupportFlags)
}
err = v.Meta.SetXattr(ctx, ino, name, value, flags)
}
Expand Down

0 comments on commit 993d518

Please sign in to comment.