forked from TrueCloudLab/restic
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:
parent
0535490618
commit
1835e988cf
1 changed files with 28 additions and 2 deletions
28
fuse/dir.go
28
fuse/dir.go
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue