From e618068a7c07aadce7f905d54f190f6afd967d3f Mon Sep 17 00:00:00 2001 From: jgfrm Date: Sat, 11 Feb 2017 22:05:23 +0100 Subject: [PATCH] Extended attribute support for fuse --- src/restic/fuse/dir.go | 18 ++++++++++++++++++ src/restic/fuse/file.go | 18 ++++++++++++++++++ src/restic/node.go | 17 +++++++++++++---- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/restic/fuse/dir.go b/src/restic/fuse/dir.go index e5f68a9d1..cb9592cc8 100644 --- a/src/restic/fuse/dir.go +++ b/src/restic/fuse/dir.go @@ -161,3 +161,21 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) { return nil, fuse.ENOENT } } + +func (d *dir) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error { + debug.Log("Listxattr(%v, %v)", d.node.Name, req.Size) + for _, attr := range d.node.ExtendedAttributes { + resp.Append(attr.Name) + } + return nil +} + +func (d *dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error { + debug.Log("Getxattr(%v, %v, %v)", d.node.Name, req.Name, req.Size) + attrval := d.node.GetExtendedAttribute(req.Name) + if attrval != nil { + resp.Xattr = attrval + return nil + } + return fuse.ErrNoXattr +} diff --git a/src/restic/fuse/file.go b/src/restic/fuse/file.go index 6bfa2e4a1..79c8ab6c1 100644 --- a/src/restic/fuse/file.go +++ b/src/restic/fuse/file.go @@ -161,3 +161,21 @@ func (f *file) Release(ctx context.Context, req *fuse.ReleaseRequest) error { } return nil } + +func (f *file) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error { + debug.Log("Listxattr(%v, %v)", f.node.Name, req.Size) + for _, attr := range f.node.ExtendedAttributes { + resp.Append(attr.Name) + } + return nil +} + +func (f *file) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error { + debug.Log("Getxattr(%v, %v, %v)", f.node.Name, req.Name, req.Size) + attrval := f.node.GetExtendedAttribute(req.Name) + if attrval != nil { + resp.Xattr = attrval + return nil + } + return fuse.ErrNoXattr +} diff --git a/src/restic/node.go b/src/restic/node.go index 034506040..b5f5afb62 100644 --- a/src/restic/node.go +++ b/src/restic/node.go @@ -103,6 +103,16 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string { return "" } +// GetExtendedAttribute gets the extended attribute. +func (node Node) GetExtendedAttribute(a string) []byte { + for _, attr := range node.ExtendedAttributes { + if attr.Name == a { + return attr.Value + } + } + return nil +} + // CreateAt creates the node at the given path and restores all the meta data. func (node *Node) CreateAt(path string, repo Repository) error { debug.Log("create node %v at %v", node.Name, path) @@ -557,6 +567,9 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error { case "symlink": node.LinkTarget, err = fs.Readlink(path) err = errors.Wrap(err, "Readlink") + if err != nil { + return err + } case "dev": node.Device = uint64(stat.rdev()) case "chardev": @@ -566,10 +579,6 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error { default: return errors.Errorf("invalid node type %q", node.Type) } - - if err { - return err - } if err = node.fillExtendedAttributes(path); err != nil { return err