MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / loadFileOrDirWithExclude

Function loadFileOrDirWithExclude

agent/app/service/device_clean.go:549–594  ·  view source on GitHub ↗
(fileOp fileUtils.FileOp, index uint, dir string, rootTree *dto.CleanTree, excludes []string)

Source from the content-addressed store, hash-verified

547}
548
549func loadFileOrDirWithExclude(fileOp fileUtils.FileOp, index uint, dir string, rootTree *dto.CleanTree, excludes []string) error {
550 index++
551 entries, err := os.ReadDir(dir)
552 if err != nil {
553 return err
554 }
555 for _, entry := range entries {
556 childPath := filepath.Join(dir, entry.Name())
557 if isExactPathMatch(childPath, excludes) {
558 continue
559 }
560 childNode := dto.CleanTree{
561 ID: uuid.NewString(),
562 Label: entry.Name(),
563 IsCheck: false,
564 IsRecommend: false,
565 CanDelete: true,
566 Name: childPath,
567 Type: "unknown_backup",
568 }
569 if entry.IsDir() {
570 if index < 4 {
571 if err = loadFileOrDirWithExclude(fileOp, index, childPath, &childNode, excludes); err != nil {
572 return err
573 }
574 childNode.Size = 0
575 for _, child := range childNode.Children {
576 childNode.Size += child.Size
577 }
578 } else {
579 itemSize, _ := fileOp.GetDirSize(childPath)
580 childNode.Size = uint64(itemSize)
581 }
582 if childNode.Size == 0 {
583 continue
584 }
585 } else {
586 info, _ := entry.Info()
587 childNode.Size = uint64(info.Size())
588 }
589
590 rootTree.Size += childNode.Size
591 rootTree.Children = append(rootTree.Children, childNode)
592 }
593 return nil
594}
595
596func isExactPathMatch(path string, excludePaths []string) bool {
597 cleanPath := filepath.Clean(path)

Callers 3

loadUnknownAppsFunction · 0.85
loadUnknownDbsFunction · 0.85
loadUnknownWebsitesFunction · 0.85

Calls 6

isExactPathMatchFunction · 0.85
ReadDirMethod · 0.80
IsDirMethod · 0.80
GetDirSizeMethod · 0.80
NameMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected