88
99 "github.com/gopasspw/gopass/internal/out"
1010 "github.com/gopasspw/gopass/internal/store"
11+ "github.com/gopasspw/gopass/internal/store/leaf"
1112 "github.com/gopasspw/gopass/internal/tree"
1213 "github.com/gopasspw/gopass/pkg/debug"
1314)
@@ -25,7 +26,7 @@ func (r *Store) List(ctx context.Context, maxDepth int) ([]string, error) {
2526// Tree returns the tree representation of the entries.
2627func (r * Store ) Tree (ctx context.Context ) (* tree.Root , error ) {
2728 root := tree .New ("gopass" )
28- addFileFunc := func (in ... string ) {
29+ addFileFunc := func (sub * leaf. Store , in ... string ) {
2930 for _ , f := range in {
3031 var ct string
3132
@@ -40,7 +41,19 @@ func (r *Store) Tree(ctx context.Context) (*tree.Root, error) {
4041 ct = "text/plain"
4142 }
4243
43- if err := root .AddFile (f , ct ); err != nil {
44+ linkTarget , isLink , err := sub .LinkTarget (ctx , f )
45+ if err != nil {
46+ out .Errorf (ctx , "Failed to resolve link target for %s: %s" , f , err )
47+
48+ continue
49+ }
50+
51+ if isLink {
52+ err = root .AddLink (f , linkTarget )
53+ } else {
54+ err = root .AddFile (f , ct )
55+ }
56+ if err != nil {
4457 out .Errorf (ctx , "Failed to add file %s to tree: %s" , f , err )
4558
4659 continue
@@ -63,7 +76,7 @@ func (r *Store) Tree(ctx context.Context) (*tree.Root, error) {
6376 }
6477
6578 debug .V (1 ).Log ("[root] adding files: %q" , sf )
66- addFileFunc (sf ... )
79+ addFileFunc (r . store , sf ... )
6780 debug .V (1 ).Log ("[root] Tree: %s" , root .Format (- 1 ))
6881 addTplFunc (r .store .ListTemplates (ctx , "" )... )
6982
@@ -86,7 +99,7 @@ func (r *Store) Tree(ctx context.Context) (*tree.Root, error) {
8699 }
87100
88101 debug .V (1 ).Log ("[%s] adding files: %q" , alias , sf )
89- addFileFunc (sf ... )
102+ addFileFunc (substore , sf ... )
90103 addTplFunc (substore .ListTemplates (ctx , alias )... )
91104 }
92105
0 commit comments