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

Function loadAppTmpDownloadTree

agent/app/service/device_clean.go:706–770  ·  view source on GitHub ↗
(fileOp fileUtils.FileOp)

Source from the content-addressed store, hash-verified

704}
705
706func loadAppTmpDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
707 appDirs, err := os.ReadDir(global.Dir.RemoteAppResourceDir)
708 if err != nil {
709 return nil
710 }
711 var res []dto.CleanTree
712 for _, appDir := range appDirs {
713 if !appDir.IsDir() {
714 continue
715 }
716 appKey := appDir.Name()
717 app, _ := appRepo.GetFirst(appRepo.WithKey(appKey))
718 if app.ID == 0 {
719 continue
720 }
721 appPath := filepath.Join(global.Dir.RemoteAppResourceDir, appKey)
722 versionDirs, err := os.ReadDir(appPath)
723 if err != nil {
724 continue
725 }
726 appDetails, _ := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID))
727 existingVersions := make(map[string]bool)
728 for _, appDetail := range appDetails {
729 existingVersions[appDetail.Version] = true
730 }
731 var missingVersions []string
732 for _, versionDir := range versionDirs {
733 if !versionDir.IsDir() {
734 continue
735 }
736
737 version := versionDir.Name()
738 if !existingVersions[version] {
739 missingVersions = append(missingVersions, version)
740 }
741 }
742 if len(missingVersions) > 0 {
743 var appTree dto.CleanTree
744 appTree.ID = uuid.NewString()
745 appTree.Label = app.Name
746 appTree.Type = "app_tmp_download"
747 appTree.Name = appKey
748 appTree.IsRecommend = true
749 appTree.IsCheck = true
750 appTree.CanDelete = false
751 for _, version := range missingVersions {
752 versionPath := filepath.Join(appPath, version)
753 size, _ := fileOp.GetDirSize(versionPath)
754 appTree.Size += uint64(size)
755 appTree.Children = append(appTree.Children, dto.CleanTree{
756 ID: uuid.NewString(),
757 Label: version,
758 Size: uint64(size),
759 IsCheck: true,
760 IsRecommend: true,
761 CanDelete: true,
762 Type: "app_tmp_download_version",
763 Name: path.Join(appKey, version),

Callers 1

loadDownloadTreeFunction · 0.85

Calls 8

ReadDirMethod · 0.80
IsDirMethod · 0.80
GetDirSizeMethod · 0.80
NameMethod · 0.65
GetFirstMethod · 0.65
WithKeyMethod · 0.65
GetByMethod · 0.65
WithAppIdMethod · 0.65

Tested by

no test coverage detected