mirror of
https://github.com/restic/restic.git
synced 2024-12-25 09:18:55 +00:00
Merge pull request #240 from restic/fix-fuse-symlinks
fuse: Display symlinks properly
This commit is contained in:
commit
ec3893e655
3 changed files with 61 additions and 27 deletions
|
@ -16,9 +16,9 @@ var _ = fs.HandleReadDirAller(&dir{})
|
||||||
var _ = fs.NodeStringLookuper(&dir{})
|
var _ = fs.NodeStringLookuper(&dir{})
|
||||||
|
|
||||||
type dir struct {
|
type dir struct {
|
||||||
repo *repository.Repository
|
repo *repository.Repository
|
||||||
children map[string]*restic.Node
|
items map[string]*restic.Node
|
||||||
inode uint64
|
inode uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(repo *repository.Repository, node *restic.Node) (*dir, error) {
|
func newDir(repo *repository.Repository, node *restic.Node) (*dir, error) {
|
||||||
|
@ -26,15 +26,15 @@ func newDir(repo *repository.Repository, node *restic.Node) (*dir, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
children := make(map[string]*restic.Node)
|
items := make(map[string]*restic.Node)
|
||||||
for _, child := range tree.Nodes {
|
for _, node := range tree.Nodes {
|
||||||
children[child.Name] = child
|
items[node.Name] = node
|
||||||
}
|
}
|
||||||
|
|
||||||
return &dir{
|
return &dir{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
children: children,
|
items: items,
|
||||||
inode: node.Inode,
|
inode: node.Inode,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,15 +43,15 @@ func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId) (*
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
children := make(map[string]*restic.Node)
|
items := make(map[string]*restic.Node)
|
||||||
for _, node := range tree.Nodes {
|
for _, node := range tree.Nodes {
|
||||||
children[node.Name] = node
|
items[node.Name] = node
|
||||||
}
|
}
|
||||||
|
|
||||||
return &dir{
|
return &dir{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
children: children,
|
items: items,
|
||||||
inode: inodeFromBackendId(snapshot.ID),
|
inode: inodeFromBackendId(snapshot.ID),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,15 +62,17 @@ func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||||
ret := make([]fuse.Dirent, 0, len(d.children))
|
ret := make([]fuse.Dirent, 0, len(d.items))
|
||||||
|
|
||||||
for _, node := range d.children {
|
for _, node := range d.items {
|
||||||
var typ fuse.DirentType
|
var typ fuse.DirentType
|
||||||
switch {
|
switch node.Type {
|
||||||
case node.Mode.IsDir():
|
case "dir":
|
||||||
typ = fuse.DT_Dir
|
typ = fuse.DT_Dir
|
||||||
case node.Mode.IsRegular():
|
case "file":
|
||||||
typ = fuse.DT_File
|
typ = fuse.DT_File
|
||||||
|
case "symlink":
|
||||||
|
typ = fuse.DT_Link
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = append(ret, fuse.Dirent{
|
ret = append(ret, fuse.Dirent{
|
||||||
|
@ -84,15 +86,17 @@ func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||||
child, ok := d.children[name]
|
node, ok := d.items[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
switch {
|
switch node.Type {
|
||||||
case child.Mode.IsDir():
|
case "dir":
|
||||||
return newDir(d.repo, child)
|
return newDir(d.repo, node)
|
||||||
case child.Mode.IsRegular():
|
case "file":
|
||||||
return newFile(d.repo, child)
|
return newFile(d.repo, node)
|
||||||
|
case "symlink":
|
||||||
|
return newLink(d.repo, node)
|
||||||
default:
|
default:
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ type file struct {
|
||||||
|
|
||||||
func newFile(repo *repository.Repository, node *restic.Node) (*file, error) {
|
func newFile(repo *repository.Repository, node *restic.Node) (*file, error) {
|
||||||
sizes := make([]uint32, len(node.Content))
|
sizes := make([]uint32, len(node.Content))
|
||||||
for i, blobId := range node.Content {
|
for i, blobID := range node.Content {
|
||||||
length, err := repo.Index().LookupSize(blobId)
|
length, err := repo.Index().LookupSize(blobID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
30
cmd/restic/fuse/link.go
Normal file
30
cmd/restic/fuse/link.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package fuse
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bazil.org/fuse"
|
||||||
|
"bazil.org/fuse/fs"
|
||||||
|
"github.com/restic/restic"
|
||||||
|
"github.com/restic/restic/repository"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Statically ensure that *file implements the given interface
|
||||||
|
var _ = fs.NodeReadlinker(&link{})
|
||||||
|
|
||||||
|
type link struct {
|
||||||
|
node *restic.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLink(repo *repository.Repository, node *restic.Node) (*link, error) {
|
||||||
|
return &link{node: node}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *link) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
|
||||||
|
return l.node.LinkTarget, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *link) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||||
|
a.Inode = l.node.Inode
|
||||||
|
a.Mode = l.node.Mode
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue