1
0
mirror of https://github.com/restic/restic.git synced 2024-06-28 08:00:52 +02:00
restic/internal/fuse/link.go

58 lines
1.3 KiB
Go
Raw Normal View History

//go:build darwin || freebsd || linux
// +build darwin freebsd linux
2015-08-16 22:27:07 +02:00
2015-07-21 21:25:05 +02:00
package fuse
import (
"context"
"github.com/anacrolix/fuse"
"github.com/anacrolix/fuse/fs"
2017-07-24 17:42:25 +02:00
"github.com/restic/restic/internal/restic"
2015-07-21 21:25:05 +02:00
)
2017-09-17 17:34:19 +02:00
// Statically ensure that *link implements the given interface
2015-07-21 21:25:05 +02:00
var _ = fs.NodeReadlinker(&link{})
type link struct {
2017-06-18 15:11:32 +02:00
root *Root
node *restic.Node
inode uint64
2015-07-21 21:25:05 +02:00
}
2022-08-19 20:29:33 +02:00
func newLink(root *Root, inode uint64, node *restic.Node) (*link, error) {
2017-06-18 15:11:32 +02:00
return &link{root: root, inode: inode, node: node}, nil
2015-07-21 21:25:05 +02:00
}
func (l *link) Readlink(_ context.Context, _ *fuse.ReadlinkRequest) (string, error) {
2015-07-21 21:25:05 +02:00
return l.node.LinkTarget, nil
}
func (l *link) Attr(_ context.Context, a *fuse.Attr) error {
2017-06-18 15:11:32 +02:00
a.Inode = l.inode
2015-07-21 21:25:05 +02:00
a.Mode = l.node.Mode
2017-06-18 15:11:32 +02:00
if !l.root.cfg.OwnerIsRoot {
a.Uid = l.node.UID
a.Gid = l.node.GID
}
2015-07-21 22:11:30 +02:00
a.Atime = l.node.AccessTime
a.Ctime = l.node.ChangeTime
a.Mtime = l.node.ModTime
2017-02-11 21:50:03 +01:00
a.Nlink = uint32(l.node.Links)
a.Size = uint64(len(l.node.LinkTarget))
a.Blocks = (a.Size + blockSize - 1) / blockSize
2017-02-11 21:50:03 +01:00
2015-07-21 21:25:05 +02:00
return nil
}
func (l *link) Listxattr(_ context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error {
2023-07-08 17:41:45 +02:00
nodeToXattrList(l.node, req, resp)
return nil
}
func (l *link) Getxattr(_ context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
2023-07-08 17:41:45 +02:00
return nodeGetXattr(l.node, req, resp)
}