Skip to content

Commit 85c69d8

Browse files
authored
fix(fs): panic when failed to get storage details (OpenListTeam#1964)
1 parent c6bd437 commit 85c69d8

File tree

7 files changed

+37
-36
lines changed

7 files changed

+37
-36
lines changed

drivers/115_open/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ func (d *Open115) GetDetails(ctx context.Context) (*model.StorageDetails, error)
331331
if err != nil {
332332
return nil, err
333333
}
334-
total, err := userInfo.RtSpaceInfo.AllTotal.Size.Int64()
334+
total, err := ParseInt64(userInfo.RtSpaceInfo.AllTotal.Size)
335335
if err != nil {
336336
return nil, err
337337
}
338-
used, err := userInfo.RtSpaceInfo.AllUse.Size.Int64()
338+
used, err := ParseInt64(userInfo.RtSpaceInfo.AllUse.Size)
339339
if err != nil {
340340
return nil, err
341341
}

drivers/115_open/util.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
package _115_open
22

3-
// do others that not defined in Driver interface
3+
import "encoding/json"
4+
5+
func ParseInt64(v json.Number) (int64, error) {
6+
i, err := v.Int64()
7+
if err == nil {
8+
return i, nil
9+
}
10+
f, e1 := v.Float64()
11+
if e1 == nil {
12+
return int64(f), nil
13+
}
14+
return int64(0), err
15+
}

drivers/alias/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
218218
}
219219
if details, ok := model.GetStorageDetails(obj); ok {
220220
objRet = &model.ObjStorageDetails{
221-
Obj: objRet,
222-
StorageDetailsWithName: *details,
221+
Obj: objRet,
222+
StorageDetails: details,
223223
}
224224
}
225225
objMap[name] = objRet

drivers/alias/util.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ func (d *Alias) listRoot(ctx context.Context, withDetails, refresh bool) []model
5050
continue
5151
}
5252
objs[idx] = &model.ObjStorageDetails{
53-
Obj: objs[idx],
54-
StorageDetailsWithName: model.StorageDetailsWithName{
55-
StorageDetails: nil,
56-
DriverName: remoteDriver.Config().Name,
57-
},
53+
Obj: objs[idx],
54+
StorageDetails: nil,
5855
}
5956
workerCount++
6057
go func(dri driver.Driver, i int) {

internal/model/storage.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,24 @@ type StorageDetails struct {
7979
DiskUsage
8080
}
8181

82-
type StorageDetailsWithName struct {
83-
*StorageDetails
84-
DriverName string `json:"driver_name"`
85-
}
86-
8782
type ObjWithStorageDetails interface {
88-
GetStorageDetails() *StorageDetailsWithName
83+
GetStorageDetails() *StorageDetails
8984
}
9085

9186
type ObjStorageDetails struct {
9287
Obj
93-
StorageDetailsWithName
88+
*StorageDetails
9489
}
9590

9691
func (o *ObjStorageDetails) Unwrap() Obj {
9792
return o.Obj
9893
}
9994

100-
func (o ObjStorageDetails) GetStorageDetails() *StorageDetailsWithName {
101-
return &o.StorageDetailsWithName
95+
func (o *ObjStorageDetails) GetStorageDetails() *StorageDetails {
96+
return o.StorageDetails
10297
}
10398

104-
func GetStorageDetails(obj Obj) (*StorageDetailsWithName, bool) {
99+
func GetStorageDetails(obj Obj) (*StorageDetails, bool) {
105100
if obj, ok := obj.(ObjWithStorageDetails); ok {
106101
return obj.GetStorageDetails(), true
107102
}

internal/op/storage.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,8 @@ func GetStorageVirtualFilesWithDetailsByPath(ctx context.Context, prefix string,
353353
return obj
354354
}
355355
ret := &model.ObjStorageDetails{
356-
Obj: obj,
357-
StorageDetailsWithName: model.StorageDetailsWithName{
358-
StorageDetails: nil,
359-
DriverName: d.Config().Name,
360-
},
356+
Obj: obj,
357+
StorageDetails: nil,
361358
}
362359
resultChan := make(chan *model.StorageDetails, 1)
363360
go func(dri driver.Driver) {

server/handles/fsread.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ type DirReq struct {
3333
}
3434

3535
type ObjResp struct {
36-
Name string `json:"name"`
37-
Size int64 `json:"size"`
38-
IsDir bool `json:"is_dir"`
39-
Modified time.Time `json:"modified"`
40-
Created time.Time `json:"created"`
41-
Sign string `json:"sign"`
42-
Thumb string `json:"thumb"`
43-
Type int `json:"type"`
44-
HashInfoStr string `json:"hashinfo"`
45-
HashInfo map[*utils.HashType]string `json:"hash_info"`
46-
MountDetails *model.StorageDetailsWithName `json:"mount_details,omitempty"`
36+
Name string `json:"name"`
37+
Size int64 `json:"size"`
38+
IsDir bool `json:"is_dir"`
39+
Modified time.Time `json:"modified"`
40+
Created time.Time `json:"created"`
41+
Sign string `json:"sign"`
42+
Thumb string `json:"thumb"`
43+
Type int `json:"type"`
44+
HashInfoStr string `json:"hashinfo"`
45+
HashInfo map[*utils.HashType]string `json:"hash_info"`
46+
MountDetails *model.StorageDetails `json:"mount_details,omitempty"`
4747
}
4848

4949
type FsListResp struct {

0 commit comments

Comments
 (0)