Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kqzh committed Aug 17, 2023
1 parent 2b3da3f commit f6b1388
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions internal/clients/spaceusage.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package clients

import (
pb "github.com/vesoft-inc/nebula-agent/v3/pkg/proto"
"os"
"path/filepath"
"strconv"

pb "github.com/vesoft-inc/nebula-agent/v3/pkg/proto"
)

type SpaceUsage struct {
Expand All @@ -19,26 +20,31 @@ func NewSpaceUsage(dataPath string) *SpaceUsage {

func (s *SpaceUsage) GetSpaceUsages() (*pb.GetSpaceUsagesResponse, error) {
spaceUsages := make([]*pb.GetSpaceUsagesResponse_SpaceUsageItem, 0)
err := filepath.Walk(s.DataPath, func(path string, info os.FileInfo, err error) error {
dirs, err := filepath.Glob(filepath.Join(s.DataPath, "*/"))
if err != nil {
return nil, err
}
for _, dir := range dirs {
id, err := strconv.Atoi(filepath.Base(dir))
if err != nil {
return err
continue
}
if !info.IsDir() {
return nil
}
id, err := strconv.Atoi(info.Name())

var size int64
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
size += info.Size()
}
return err
})
if err != nil {
return nil
return nil, err
}

spaceUsages = append(spaceUsages, &pb.GetSpaceUsagesResponse_SpaceUsageItem{
Id: int64(id),
Usage: info.Size(),
Usage: size,
})
return nil
})
if err != nil {
return nil, err
}

return &pb.GetSpaceUsagesResponse{SpaceUsages: spaceUsages}, nil
Expand Down

0 comments on commit f6b1388

Please sign in to comment.