2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-10 15:21:03 +00:00

Merge pull request #1465 from restic/fuse-handle-others

fuse: Handle/format all node types correctly
This commit is contained in:
Alexander Neumann 2017-12-03 18:25:49 +01:00
commit 69fcb604c8
4 changed files with 78 additions and 13 deletions

View File

@ -68,17 +68,29 @@ func formatNode(prefix string, n *restic.Node, long bool) string {
return filepath.Join(prefix, n.Name)
}
var mode os.FileMode
var target string
switch n.Type {
case "file":
return fmt.Sprintf("%s %5d %5d %6d %s %s",
n.Mode, n.UID, n.GID, n.Size, n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name))
mode = 0
case "dir":
return fmt.Sprintf("%s %5d %5d %6d %s %s",
n.Mode|os.ModeDir, n.UID, n.GID, n.Size, n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name))
mode = os.ModeDir
case "symlink":
return fmt.Sprintf("%s %5d %5d %6d %s %s -> %s",
n.Mode|os.ModeSymlink, n.UID, n.GID, n.Size, n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name), n.LinkTarget)
default:
return fmt.Sprintf("<Node(%s) %s>", n.Type, n.Name)
mode = os.ModeSymlink
target = fmt.Sprintf(" -> %v", n.LinkTarget)
case "dev":
mode = os.ModeDevice
case "chardev":
mode = os.ModeDevice | os.ModeCharDevice
case "fifo":
mode = os.ModeNamedPipe
case "socket":
mode = os.ModeSocket
}
return fmt.Sprintf("%s %5d %5d %6d %s %s%s",
mode|n.Mode, n.UID, n.GID, n.Size,
n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name),
target)
}

View File

@ -185,6 +185,8 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
return newFile(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node)
case "symlink":
return newLink(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node)
case "dev", "chardev", "fifo", "socket":
return newOther(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node)
default:
debug.Log(" node %v has unknown type %v", name, node.Type)
return nil, fuse.ENOENT

41
internal/fuse/other.go Normal file
View File

@ -0,0 +1,41 @@
// +build !openbsd
// +build !windows
package fuse
import (
"bazil.org/fuse"
"github.com/restic/restic/internal/restic"
"golang.org/x/net/context"
)
type other struct {
root *Root
node *restic.Node
inode uint64
}
func newOther(ctx context.Context, root *Root, inode uint64, node *restic.Node) (*other, error) {
return &other{root: root, inode: inode, node: node}, nil
}
func (l *other) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
return l.node.LinkTarget, nil
}
func (l *other) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = l.inode
a.Mode = l.node.Mode
if !l.root.cfg.OwnerIsRoot {
a.Uid = l.node.UID
a.Gid = l.node.GID
}
a.Atime = l.node.AccessTime
a.Ctime = l.node.ChangeTime
a.Mtime = l.node.ModTime
a.Nlink = uint32(l.node.Links)
return nil
}

View File

@ -61,16 +61,26 @@ func (n Nodes) Less(i, j int) bool { return n[i].Name < n[j].Name }
func (n Nodes) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
func (node Node) String() string {
var mode os.FileMode
switch node.Type {
case "file":
return fmt.Sprintf("%s %5d %5d %6d %s %s",
node.Mode, node.UID, node.GID, node.Size, node.ModTime, node.Name)
mode = 0
case "dir":
return fmt.Sprintf("%s %5d %5d %6d %s %s",
node.Mode|os.ModeDir, node.UID, node.GID, node.Size, node.ModTime, node.Name)
mode = os.ModeDir
case "symlink":
mode = os.ModeSymlink
case "dev":
mode = os.ModeDevice
case "chardev":
mode = os.ModeDevice | os.ModeCharDevice
case "fifo":
mode = os.ModeNamedPipe
case "socket":
mode = os.ModeSocket
}
return fmt.Sprintf("<Node(%s) %s>", node.Type, node.Name)
return fmt.Sprintf("%s %5d %5d %6d %s %s",
mode|node.Mode, node.UID, node.GID, node.Size, node.ModTime, node.Name)
}
// NodeFromFileInfo returns a new node from the given path and FileInfo. It