Skip to content

Commit 6fe9af7

Browse files
authored
fix(alias): stabilize list root result (#1401)
1 parent 2edc446 commit 6fe9af7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

drivers/alias/driver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
type Alias struct {
2424
model.Storage
2525
Addition
26+
rootOrder []string
2627
pathMap map[string][]string
2728
autoFlatten bool
2829
oneKey string
@@ -40,13 +41,18 @@ func (d *Alias) Init(ctx context.Context) error {
4041
if d.Paths == "" {
4142
return errors.New("paths is required")
4243
}
44+
paths := strings.Split(d.Paths, "\n")
45+
d.rootOrder = make([]string, 0, len(paths))
4346
d.pathMap = make(map[string][]string)
44-
for _, path := range strings.Split(d.Paths, "\n") {
47+
for _, path := range paths {
4548
path = strings.TrimSpace(path)
4649
if path == "" {
4750
continue
4851
}
4952
k, v := getPair(path)
53+
if _, ok := d.pathMap[k]; !ok {
54+
d.rootOrder = append(d.rootOrder, k)
55+
}
5056
d.pathMap[k] = append(d.pathMap[k], v)
5157
}
5258
if len(d.pathMap) == 1 {
@@ -62,6 +68,7 @@ func (d *Alias) Init(ctx context.Context) error {
6268
}
6369

6470
func (d *Alias) Drop(ctx context.Context) error {
71+
d.rootOrder = nil
6572
d.pathMap = nil
6673
return nil
6774
}

drivers/alias/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import (
1919
func (d *Alias) listRoot(ctx context.Context, withDetails bool) []model.Obj {
2020
var objs []model.Obj
2121
var wg sync.WaitGroup
22-
for k, v := range d.pathMap {
22+
for _, k := range d.rootOrder {
2323
obj := model.Object{
2424
Name: k,
2525
IsFolder: true,
2626
Modified: d.Modified,
2727
}
2828
idx := len(objs)
2929
objs = append(objs, &obj)
30+
v := d.pathMap[k]
3031
if !withDetails || len(v) != 1 {
3132
continue
3233
}

0 commit comments

Comments
 (0)