1
0
mirror of https://github.com/restic/restic.git synced 2025-03-16 08:20:52 +00:00

fuse: Replace special node names with their content

This is the companion fix for  and allows mounting repositories with
special directory names directly below the snapshot.

Closes 
This commit is contained in:
Alexander Neumann 2016-02-07 19:50:17 +01:00
parent 0535490618
commit 1835e988cf

@ -45,15 +45,41 @@ func newDir(repo *repository.Repository, node *restic.Node, ownerIsRoot bool) (*
}, nil }, nil
} }
// replaceSpecialNodes replaces nodes with name "." and "/" by their contents.
// Otherwise, the node is returned.
func replaceSpecialNodes(repo *repository.Repository, node *restic.Node) ([]*restic.Node, error) {
if node.Type != "dir" || node.Subtree == nil {
return []*restic.Node{node}, nil
}
if node.Name != "." && node.Name != "/" {
return []*restic.Node{node}, nil
}
tree, err := restic.LoadTree(repo, *node.Subtree)
if err != nil {
return nil, err
}
return tree.Nodes, nil
}
func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId, ownerIsRoot bool) (*dir, error) { func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId, ownerIsRoot bool) (*dir, error) {
tree, err := restic.LoadTree(repo, *snapshot.Tree) tree, err := restic.LoadTree(repo, *snapshot.Tree)
if err != nil { if err != nil {
return nil, err return nil, err
} }
items := make(map[string]*restic.Node) items := make(map[string]*restic.Node)
for _, node := range tree.Nodes { for _, n := range tree.Nodes {
nodes, err := replaceSpecialNodes(repo, n)
if err != nil {
return nil, err
}
for _, node := range nodes {
items[node.Name] = node items[node.Name] = node
} }
}
return &dir{ return &dir{
repo: repo, repo: repo,