mirror of
https://github.com/octoleo/restic.git
synced 2024-11-13 00:36:35 +00:00
Merge pull request #1465 from restic/fuse-handle-others
fuse: Handle/format all node types correctly
This commit is contained in:
commit
69fcb604c8
@ -68,17 +68,29 @@ func formatNode(prefix string, n *restic.Node, long bool) string {
|
|||||||
return filepath.Join(prefix, n.Name)
|
return filepath.Join(prefix, n.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mode os.FileMode
|
||||||
|
var target string
|
||||||
|
|
||||||
switch n.Type {
|
switch n.Type {
|
||||||
case "file":
|
case "file":
|
||||||
return fmt.Sprintf("%s %5d %5d %6d %s %s",
|
mode = 0
|
||||||
n.Mode, n.UID, n.GID, n.Size, n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name))
|
|
||||||
case "dir":
|
case "dir":
|
||||||
return fmt.Sprintf("%s %5d %5d %6d %s %s",
|
mode = os.ModeDir
|
||||||
n.Mode|os.ModeDir, n.UID, n.GID, n.Size, n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name))
|
|
||||||
case "symlink":
|
case "symlink":
|
||||||
return fmt.Sprintf("%s %5d %5d %6d %s %s -> %s",
|
mode = os.ModeSymlink
|
||||||
n.Mode|os.ModeSymlink, n.UID, n.GID, n.Size, n.ModTime.Format(TimeFormat), filepath.Join(prefix, n.Name), n.LinkTarget)
|
target = fmt.Sprintf(" -> %v", n.LinkTarget)
|
||||||
default:
|
case "dev":
|
||||||
return fmt.Sprintf("<Node(%s) %s>", n.Type, n.Name)
|
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)
|
||||||
}
|
}
|
||||||
|
@ -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)
|
return newFile(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node)
|
||||||
case "symlink":
|
case "symlink":
|
||||||
return newLink(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node)
|
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:
|
default:
|
||||||
debug.Log(" node %v has unknown type %v", name, node.Type)
|
debug.Log(" node %v has unknown type %v", name, node.Type)
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
|
41
internal/fuse/other.go
Normal file
41
internal/fuse/other.go
Normal 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
|
||||||
|
}
|
@ -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 (n Nodes) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
|
||||||
|
|
||||||
func (node Node) String() string {
|
func (node Node) String() string {
|
||||||
|
var mode os.FileMode
|
||||||
switch node.Type {
|
switch node.Type {
|
||||||
case "file":
|
case "file":
|
||||||
return fmt.Sprintf("%s %5d %5d %6d %s %s",
|
mode = 0
|
||||||
node.Mode, node.UID, node.GID, node.Size, node.ModTime, node.Name)
|
|
||||||
case "dir":
|
case "dir":
|
||||||
return fmt.Sprintf("%s %5d %5d %6d %s %s",
|
mode = os.ModeDir
|
||||||
node.Mode|os.ModeDir, node.UID, node.GID, node.Size, node.ModTime, node.Name)
|
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
|
// NodeFromFileInfo returns a new node from the given path and FileInfo. It
|
||||||
|
Loading…
Reference in New Issue
Block a user