mirror of
https://github.com/restic/restic.git
synced 2025-02-28 16:56:24 +00:00
fs: prepare fd based metadataHandle
Add the skeleton, but leave filling in the details to later commits.
This commit is contained in:
parent
e70fa4f9f5
commit
ea1446f50b
4 changed files with 78 additions and 11 deletions
36
internal/fs/meta_fd.go
Normal file
36
internal/fs/meta_fd.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
//go:build darwin || linux || windows
|
||||||
|
|
||||||
|
package fs
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
type fdMetadataHandle struct {
|
||||||
|
name string
|
||||||
|
f *os.File
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ metadataHandle = &fdMetadataHandle{}
|
||||||
|
|
||||||
|
func newFdMetadataHandle(name string, f *os.File) *fdMetadataHandle {
|
||||||
|
return &fdMetadataHandle{
|
||||||
|
name: name,
|
||||||
|
f: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) Name() string {
|
||||||
|
return p.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) Stat() (*ExtendedFileInfo, error) {
|
||||||
|
fi, err := p.f.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return extendedStat(fi), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) Readlink() (string, error) {
|
||||||
|
// FIXME
|
||||||
|
return os.Readlink(fixpath(p.name))
|
||||||
|
}
|
14
internal/fs/meta_fd_notwindows.go
Normal file
14
internal/fs/meta_fd_notwindows.go
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//go:build darwin || linux
|
||||||
|
|
||||||
|
package fs
|
||||||
|
|
||||||
|
import "github.com/restic/restic/internal/restic"
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) Xattr(ignoreListError bool) ([]restic.ExtendedAttribute, error) {
|
||||||
|
// FIXME
|
||||||
|
return xattrFromPath(p.Name(), ignoreListError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) SecurityDescriptor() (*[]byte, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
|
@ -8,23 +8,26 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *pathMetadataHandle) Xattr(_ bool) ([]restic.ExtendedAttribute, error) {
|
func (p *pathMetadataHandle) Xattr(_ bool) ([]restic.ExtendedAttribute, error) {
|
||||||
allowExtended, err := checkAndStoreEASupport(p.name)
|
return xattrFromPath(p.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func xattrFromPath(path string) ([]restic.ExtendedAttribute, error) {
|
||||||
|
allowExtended, err := checkAndStoreEASupport(path)
|
||||||
if err != nil || !allowExtended {
|
if err != nil || !allowExtended {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileHandle windows.Handle
|
var fileHandle windows.Handle
|
||||||
if fileHandle, err = openHandleForEA(p.name, false); err != nil {
|
if fileHandle, err = openHandleForEA(path, false); err != nil {
|
||||||
return nil, errors.Errorf("get EA failed while opening file handle for path %v, with: %v", p.name, err)
|
return nil, errors.Errorf("get EA failed while opening file handle for path %v, with: %v", path, err)
|
||||||
}
|
}
|
||||||
defer closeFileHandle(fileHandle, p.name)
|
defer closeFileHandle(fileHandle, path)
|
||||||
|
|
||||||
//Get the windows Extended Attributes using the file handle
|
//Get the windows Extended Attributes using the file handle
|
||||||
var extAtts []extendedAttribute
|
var extAtts []extendedAttribute
|
||||||
extAtts, err = fgetEA(fileHandle)
|
extAtts, err = fgetEA(fileHandle)
|
||||||
debug.Log("fillExtendedAttributes(%v) %v", p.name, extAtts)
|
debug.Log("fillExtendedAttributes(%v) %v", path, extAtts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("get EA failed for path %v, with: %v", p.name, err)
|
return nil, errors.Errorf("get EA failed for path %v, with: %v", path, err)
|
||||||
}
|
}
|
||||||
if len(extAtts) == 0 {
|
if len(extAtts) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -45,3 +48,13 @@ func (p *pathMetadataHandle) Xattr(_ bool) ([]restic.ExtendedAttribute, error) {
|
||||||
func (p *pathMetadataHandle) SecurityDescriptor() (*[]byte, error) {
|
func (p *pathMetadataHandle) SecurityDescriptor() (*[]byte, error) {
|
||||||
return getSecurityDescriptor(p.name)
|
return getSecurityDescriptor(p.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) Xattr(_ bool) ([]restic.ExtendedAttribute, error) {
|
||||||
|
// FIXME
|
||||||
|
return xattrFromPath(p.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *fdMetadataHandle) SecurityDescriptor() (*[]byte, error) {
|
||||||
|
// FIXME
|
||||||
|
return getSecurityDescriptor(p.name)
|
||||||
|
}
|
||||||
|
|
|
@ -12,8 +12,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *pathMetadataHandle) Xattr(ignoreListError bool) ([]restic.ExtendedAttribute, error) {
|
func (p *pathMetadataHandle) Xattr(ignoreListError bool) ([]restic.ExtendedAttribute, error) {
|
||||||
xattrs, err := listxattr(p.name)
|
return xattrFromPath(p.Name(), ignoreListError)
|
||||||
debug.Log("fillExtendedAttributes(%v) %v %v", p.name, xattrs, err)
|
}
|
||||||
|
|
||||||
|
func xattrFromPath(path string, ignoreListError bool) ([]restic.ExtendedAttribute, error) {
|
||||||
|
xattrs, err := listxattr(path)
|
||||||
|
debug.Log("fillExtendedAttributes(%v) %v %v", path, xattrs, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ignoreListError && isListxattrPermissionError(err) {
|
if ignoreListError && isListxattrPermissionError(err) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -23,9 +27,9 @@ func (p *pathMetadataHandle) Xattr(ignoreListError bool) ([]restic.ExtendedAttri
|
||||||
|
|
||||||
extendedAttrs := make([]restic.ExtendedAttribute, 0, len(xattrs))
|
extendedAttrs := make([]restic.ExtendedAttribute, 0, len(xattrs))
|
||||||
for _, attr := range xattrs {
|
for _, attr := range xattrs {
|
||||||
attrVal, err := getxattr(p.name, attr)
|
attrVal, err := getxattr(path, attr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "can not obtain extended attribute %v for %v:\n", attr, p.name)
|
fmt.Fprintf(os.Stderr, "can not obtain extended attribute %v for %v:\n", attr, path)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
attr := restic.ExtendedAttribute{
|
attr := restic.ExtendedAttribute{
|
||||||
|
|
Loading…
Reference in a new issue