Skip to content

Commit d1c2368

Browse files
committed
fix(driver/139): remove root path stripping in Init method
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 6650de6 commit d1c2368

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

drivers/139/driver.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ func (d *Yun139) Init(ctx context.Context) error {
122122
case MetaFamily:
123123
if len(d.Addition.RootFolderID) == 0 {
124124
// Attempt to obtain data.path as the root via a query and persist it.
125-
d.RootFolderID = stripRootPath(d.RootFolderID)
126125
if root, err := d.getFamilyRootPath(d.CloudID); err == nil && root != "" {
127126
d.RootFolderID = root
128127
op.MustSaveDriverStorage(d)

drivers/139/util.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,14 +1379,6 @@ func (d *Yun139) dirPath(dir model.Obj) string {
13791379
return path.Join(p, id)
13801380
}
13811381

1382-
// helper to strip "root:/" or "root:" prefix
1383-
func stripRootPath(s string) string {
1384-
s = strings.TrimSpace(s)
1385-
s = strings.TrimPrefix(s, "root:/")
1386-
s = strings.TrimPrefix(s, "root:")
1387-
return s
1388-
}
1389-
13901382
// getFamilyRootPath 查询 family 的上层 path(data.path)
13911383
// 返回值已去除前缀 "root:/"(或 "root:"),直接返回纯 ID 或 path 部分,便于持久化为 RootFolderID。
13921384
func (d *Yun139) getFamilyRootPath(cloudID string) (string, error) {
@@ -1417,14 +1409,21 @@ func (d *Yun139) getFamilyRootPath(cloudID string) (string, error) {
14171409
if dataObj == nil {
14181410
return "", fmt.Errorf("invalid family response data")
14191411
}
1412+
// helper to strip "root:/" or "root:" prefix
1413+
stripRoot := func(s string) string {
1414+
s = strings.TrimSpace(s)
1415+
s = strings.TrimPrefix(s, "root:/")
1416+
s = strings.TrimPrefix(s, "root:")
1417+
return s
1418+
}
14201419
if p, ok := dataObj["path"].(string); ok && p != "" {
1421-
return stripRootPath(p), nil
1420+
return stripRoot(p), nil
14221421
}
14231422
// 回退:有时 path 在 cloudCatalogList.catalogList 中
14241423
if cl, ok := dataObj["cloudCatalogList"].([]interface{}); ok && len(cl) > 0 {
14251424
if first, ok := cl[0].(map[string]interface{}); ok {
14261425
if p, ok := first["path"].(string); ok && p != "" {
1427-
return stripRootPath(p), nil
1426+
return stripRoot(p), nil
14281427
}
14291428
}
14301429
}

0 commit comments

Comments
 (0)