Skip to content

Commit

Permalink
chore: make walk func standalone
Browse files Browse the repository at this point in the history
Signed-off-by: zzy987 <[email protected]>
  • Loading branch information
zzy987 committed Aug 30, 2021
1 parent 34e8569 commit 8093cb1
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions cdnsystem/supervisor/cdn/storage/hybrid/hybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (h *hybridStorageMgr) StatDownloadFile(taskID string) (*storedriver.Storage
func (h *hybridStorageMgr) GetFreeSpace() int64 {
var memoryFreeSpace, diskFreeSpace int64
remainder := atomic.NewInt64(0)
h.diskDriver.Walk(&storedriver.Raw{
r := &storedriver.Raw{
WalkFn: func(filePath string, info os.FileInfo, err error) error {
if fileutils.IsRegular(filePath) {
taskID := strings.Split(path.Base(filePath), ".")[0]
Expand All @@ -318,7 +318,9 @@ func (h *hybridStorageMgr) GetFreeSpace() int64 {
}
return nil
},
})
}

h.diskDriver.Walk(r)
dFree, err := h.diskDriver.GetFreeSpace()
if err != nil {
diskFreeSpace = 0
Expand All @@ -328,28 +330,7 @@ func (h *hybridStorageMgr) GetFreeSpace() int64 {

if h.hasShm {
remainder = atomic.NewInt64(0)
h.memoryDriver.Walk(&storedriver.Raw{
WalkFn: func(filePath string, info os.FileInfo, err error) error {
if fileutils.IsRegular(filePath) {
taskID := strings.Split(path.Base(filePath), ".")[0]
task, exist := h.taskMgr.Exist(taskID)
if exist {
var totalLen int64 = 0
if task.CdnFileLength > 0 {
totalLen = task.CdnFileLength
} else {
totalLen = task.SourceFileLength
}
if totalLen > 0 {
remainder.Add(totalLen - info.Size())
}
} else {
logger.Warnf("failed to get task: %s", taskID)
}
}
return nil
},
})
h.memoryDriver.Walk(r)
memoryFreeSpace = h.getMemoryUsableSpace().ToNumber() - remainder.Load()
}

Expand Down

0 comments on commit 8093cb1

Please sign in to comment.