2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

fuse: Replace special node names with their content

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

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

View File

@ -45,15 +45,41 @@ func newDir(repo *repository.Repository, node *restic.Node, ownerIsRoot bool) (*
}, 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) {
tree, err := restic.LoadTree(repo, *snapshot.Tree)
if err != nil {
return nil, err
}
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
}
}
return &dir{
repo: repo,