mirror of
https://github.com/octoleo/restic.git
synced 2025-01-11 10:18:10 +00:00
Use functions to create names
This commit is contained in:
parent
a016f82051
commit
3731a94367
@ -177,14 +177,7 @@ func (sn *snapshots) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tree, err := restic.LoadTree(sn.repo, snapshot.Tree)
|
return newDirFromSnapshot(sn.repo, snapshot)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &dir{
|
|
||||||
repo: sn.repo,
|
|
||||||
tree: tree,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Statically ensure that *dir implement those interface
|
// Statically ensure that *dir implement those interface
|
||||||
@ -193,10 +186,44 @@ var _ = fs.NodeStringLookuper(&dir{})
|
|||||||
|
|
||||||
type dir struct {
|
type dir struct {
|
||||||
repo *repository.Repository
|
repo *repository.Repository
|
||||||
tree *restic.Tree
|
children map[string]*restic.Node
|
||||||
inode uint64
|
inode uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newDir(repo *repository.Repository, node *restic.Node) (*dir, error) {
|
||||||
|
tree, err := restic.LoadTree(repo, node.Subtree)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
children := make(map[string]*restic.Node)
|
||||||
|
for _, child := range tree.Nodes {
|
||||||
|
children[child.Name] = child
|
||||||
|
}
|
||||||
|
|
||||||
|
return &dir{
|
||||||
|
repo: repo,
|
||||||
|
children: children,
|
||||||
|
inode: node.Inode,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDirFromSnapshot(repo *repository.Repository, snapshot snapshotWithId) (*dir, error) {
|
||||||
|
tree, err := restic.LoadTree(repo, snapshot.Tree)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
children := make(map[string]*restic.Node)
|
||||||
|
for _, node := range tree.Nodes {
|
||||||
|
children[node.Name] = node
|
||||||
|
}
|
||||||
|
|
||||||
|
return &dir{
|
||||||
|
repo: repo,
|
||||||
|
children: children,
|
||||||
|
inode: binary.BigEndian.Uint64(snapshot.ID),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
|
func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||||
a.Inode = d.inode
|
a.Inode = d.inode
|
||||||
a.Mode = os.ModeDir | 0555
|
a.Mode = os.ModeDir | 0555
|
||||||
@ -204,9 +231,9 @@ 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.tree.Nodes))
|
ret := make([]fuse.Dirent, 0, len(d.children))
|
||||||
|
|
||||||
for _, node := range d.tree.Nodes {
|
for _, node := range d.children {
|
||||||
var typ fuse.DirentType
|
var typ fuse.DirentType
|
||||||
switch {
|
switch {
|
||||||
case node.Mode.IsDir():
|
case node.Mode.IsDir():
|
||||||
@ -226,25 +253,18 @@ 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) {
|
||||||
for _, node := range d.tree.Nodes {
|
child, ok := d.children[name]
|
||||||
if node.Name == name {
|
if !ok {
|
||||||
|
return nil, fuse.ENOENT
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case node.Mode.IsDir():
|
case child.Mode.IsDir():
|
||||||
subtree, err := restic.LoadTree(d.repo, node.Subtree)
|
return newDir(d.repo, child)
|
||||||
if err != nil {
|
case child.Mode.IsRegular():
|
||||||
return nil, err
|
return newFile(d.repo, child)
|
||||||
|
default:
|
||||||
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
return &dir{
|
|
||||||
repo: d.repo,
|
|
||||||
tree: subtree,
|
|
||||||
inode: binary.BigEndian.Uint64(node.Subtree[:8]),
|
|
||||||
}, nil
|
|
||||||
case node.Mode.IsRegular():
|
|
||||||
return makeFile(d.repo, node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Statically ensure that *file implements the given interface
|
// Statically ensure that *file implements the given interface
|
||||||
@ -260,7 +280,7 @@ type file struct {
|
|||||||
clearContent [][]byte
|
clearContent [][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFile(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().Lookup(blobId)
|
_, _, _, length, err := repo.Index().Lookup(blobId)
|
||||||
|
Loading…
Reference in New Issue
Block a user