mirror of
https://github.com/restic/restic.git
synced 2025-01-18 13:31:08 +00:00
fs: correctly handle O_NOFOLLOW for xattr / generic attribute retrieval
This commit is contained in:
parent
67c0387cfe
commit
c0d727dfed
4 changed files with 29 additions and 6 deletions
|
@ -262,7 +262,7 @@ func TestPathSupportsExtendedAttributes(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
handle, err := openMetadataHandle(tc.path, false)
|
||||
handle, err := openMetadataHandle(tc.path, 0)
|
||||
rtest.OK(t, err)
|
||||
supported, err := handleSupportsExtendedAttributes(windows.Handle(handle.Fd()))
|
||||
if err != nil {
|
||||
|
@ -276,7 +276,7 @@ func TestPathSupportsExtendedAttributes(t *testing.T) {
|
|||
|
||||
// Test with an invalid path
|
||||
|
||||
handle, err := openMetadataHandle("Z:\\NonExistentPath-UAS664da5s4dyu56das45f5as", false)
|
||||
handle, err := openMetadataHandle("Z:\\NonExistentPath-UAS664da5s4dyu56das45f5as", 0)
|
||||
rtest.OK(t, err)
|
||||
_, err = handleSupportsExtendedAttributes(windows.Handle(handle.Fd()))
|
||||
if err == nil {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *pathMetadataHandle) Xattr(_ bool) ([]restic.ExtendedAttribute, error) {
|
||||
f, err := openMetadataHandle(p.name, false)
|
||||
f, err := openMetadataHandle(p.name, p.flag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func xattrFromHandle(path string, handle windows.Handle) ([]restic.ExtendedAttri
|
|||
}
|
||||
|
||||
func (p *pathMetadataHandle) SecurityDescriptor() (buf *[]byte, err error) {
|
||||
f, err := openMetadataHandle(p.name, 0)
|
||||
f, err := openMetadataHandle(p.name, p.flag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -15,8 +15,18 @@ func (p *pathMetadataHandle) Xattr(ignoreListError bool) ([]restic.ExtendedAttri
|
|||
path := p.Name()
|
||||
return xattrFromPath(
|
||||
path,
|
||||
func() ([]string, error) { return listxattr(path) },
|
||||
func(attr string) ([]byte, error) { return getxattr(path, attr) },
|
||||
func() ([]string, error) {
|
||||
if (p.flag & O_NOFOLLOW) != 0 {
|
||||
return llistxattr(path)
|
||||
}
|
||||
return listxattr(path)
|
||||
},
|
||||
func(attr string) ([]byte, error) {
|
||||
if (p.flag & O_NOFOLLOW) != 0 {
|
||||
return lgetxattr(path, attr)
|
||||
}
|
||||
return getxattr(path, attr)
|
||||
},
|
||||
ignoreListError,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ func fgetxattr(f *os.File, name string) (b []byte, err error) {
|
|||
|
||||
// getxattr retrieves extended attribute data associated with path.
|
||||
func getxattr(path string, name string) (b []byte, err error) {
|
||||
b, err = xattr.Get(path, name)
|
||||
return b, handleXattrErr(err)
|
||||
}
|
||||
|
||||
// lgetxattr retrieves extended attribute data associated with path.
|
||||
func lgetxattr(path string, name string) (b []byte, err error) {
|
||||
b, err = xattr.LGet(path, name)
|
||||
return b, handleXattrErr(err)
|
||||
}
|
||||
|
@ -70,6 +76,13 @@ func flistxattr(f *os.File) (l []string, err error) {
|
|||
// listxattr retrieves a list of names of extended attributes associated with the
|
||||
// given path in the file system.
|
||||
func listxattr(path string) ([]string, error) {
|
||||
l, err := xattr.List(path)
|
||||
return l, handleXattrErr(err)
|
||||
}
|
||||
|
||||
// llistxattr retrieves a list of names of extended attributes associated with the
|
||||
// given path in the file system.
|
||||
func llistxattr(path string) ([]string, error) {
|
||||
l, err := xattr.LList(path)
|
||||
return l, handleXattrErr(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue