Skip to content

Commit 099896d

Browse files
feat: add app temporary download file cleanup option to cache cleaning (#11460)
1 parent aa1bc6f commit 099896d

File tree

12 files changed

+108
-2
lines changed

12 files changed

+108
-2
lines changed

agent/app/service/device_clean.go

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ func (u *DeviceService) Clean(req []dto.Clean) {
194194
_, _ = dropVolumes()
195195
case "build_cache":
196196
_, _ = dropBuildCache()
197+
case "app_tmp_download_version":
198+
dropFileOrDir(path.Join(global.Dir.RemoteAppResourceDir, item.Name))
197199
}
198200
}
199201

@@ -612,6 +614,22 @@ func loadDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
612614
uploadTreeData := loadTreeWithAllFile(true, path5, "download", path5, fileOp)
613615
treeData = append(treeData, uploadTreeData...)
614616

617+
appTmpDownloadTree := loadAppTmpDownloadTree(fileOp)
618+
if len(appTmpDownloadTree) > 0 {
619+
parentTree := dto.CleanTree{
620+
ID: uuid.NewString(),
621+
Label: "app_tmp_download",
622+
IsCheck: true,
623+
IsRecommend: true,
624+
Type: "app_tmp_download",
625+
Name: "apps",
626+
}
627+
for _, child := range appTmpDownloadTree {
628+
parentTree.Size += child.Size
629+
}
630+
parentTree.Children = appTmpDownloadTree
631+
treeData = append(treeData, parentTree)
632+
}
615633
return treeData
616634
}
617635

@@ -665,6 +683,70 @@ func loadWebsiteLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
665683
return res
666684
}
667685

686+
func loadAppTmpDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
687+
appDirs, err := os.ReadDir(global.Dir.RemoteAppResourceDir)
688+
if err != nil {
689+
return nil
690+
}
691+
var res []dto.CleanTree
692+
for _, appDir := range appDirs {
693+
if !appDir.IsDir() {
694+
continue
695+
}
696+
appKey := appDir.Name()
697+
app, _ := appRepo.GetFirst(appRepo.WithKey(appKey))
698+
if app.ID == 0 {
699+
continue
700+
}
701+
appPath := filepath.Join(global.Dir.RemoteAppResourceDir, appKey)
702+
versionDirs, err := os.ReadDir(appPath)
703+
if err != nil {
704+
continue
705+
}
706+
appDetails, _ := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID))
707+
existingVersions := make(map[string]bool)
708+
for _, appDetail := range appDetails {
709+
existingVersions[appDetail.Version] = true
710+
}
711+
var missingVersions []string
712+
for _, versionDir := range versionDirs {
713+
if !versionDir.IsDir() {
714+
continue
715+
}
716+
717+
version := versionDir.Name()
718+
if !existingVersions[version] {
719+
missingVersions = append(missingVersions, version)
720+
}
721+
}
722+
if len(missingVersions) > 0 {
723+
var appTree dto.CleanTree
724+
appTree.ID = uuid.NewString()
725+
appTree.Label = app.Name
726+
appTree.Type = "app_tmp_download"
727+
appTree.Name = appKey
728+
appTree.IsRecommend = true
729+
appTree.IsCheck = true
730+
for _, version := range missingVersions {
731+
versionPath := filepath.Join(appPath, version)
732+
size, _ := fileOp.GetDirSize(versionPath)
733+
appTree.Size += uint64(size)
734+
appTree.Children = append(appTree.Children, dto.CleanTree{
735+
ID: uuid.NewString(),
736+
Label: version,
737+
Size: uint64(size),
738+
IsCheck: true,
739+
IsRecommend: true,
740+
Type: "app_tmp_download_version",
741+
Name: path.Join(appKey, version),
742+
})
743+
}
744+
res = append(res, appTree)
745+
}
746+
}
747+
return res
748+
}
749+
668750
func loadContainerTree() []dto.CleanTree {
669751
var treeData []dto.CleanTree
670752
client, err := docker.NewDockerClient()
@@ -786,7 +868,7 @@ func loadTreeWithAllFile(isCheck bool, originalPath, treeType, pathItem string,
786868
ID: uuid.NewString(),
787869
Label: file.Name(),
788870
Type: treeType,
789-
Size: uint64(size),
871+
Size: size,
790872
Name: name,
791873
IsCheck: isCheck,
792874
IsRecommend: isCheck,

frontend/src/lang/modules/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,8 @@ const message = {
22332233
dockerHelper: 'Files such as containers, images, volumes, build cache, etc.',
22342234
volumes: 'Volumes',
22352235
buildCache: 'Container Build Cache',
2236+
2237+
appTmpDownload: 'App temporary download file',
22362238
},
22372239
app: {
22382240
app: 'Application | Applications',

frontend/src/lang/modules/es-es.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,8 @@ const message = {
22462246
dockerHelper: 'Archivos como contenedores, imágenes, volúmenes, caché de construcción, etc.',
22472247
volumes: 'Volúmenes',
22482248
buildCache: 'Caché de build de contenedores',
2249+
2250+
appTmpDownload: 'Archivo de descarga temporal de la aplicación',
22492251
},
22502252
app: {
22512253
app: 'Aplicación | Aplicaciones',

frontend/src/lang/modules/ja.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ const message = {
21532153
dockerHelper: 'コンテナ、イメージ、ボリューム、ビルドキャッシュなどのファイル',
21542154
volumes: 'ボリューム',
21552155
buildCache: 'コンテナビルドキャッシュ',
2156+
2157+
appTmpDownload: 'Archivo de descarga temporal de la aplicación',
21562158
},
21572159
app: {
21582160
app: 'アプリケーション|アプリケーション',

frontend/src/lang/modules/ko.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,8 @@ const message = {
21172117
dockerHelper: '컨테이너, 이미지, 볼륨, 빌드 캐시 등의 파일',
21182118
volumes: '볼륨',
21192119
buildCache: '컨테이너 빌드 캐시',
2120+
2121+
appTmpDownload: '앱 임시 다운로드 파일',
21202122
},
21212123
app: {
21222124
app: '애플리케이션 | 애플리케이션들',

frontend/src/lang/modules/ms.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,8 @@ const message = {
22122212
dockerHelper: 'Fail seperti bekas, imej, isipadu, cache binaan, dsb.',
22132213
volumes: 'Isipadu',
22142214
buildCache: 'Cache Pembinaan Kontena',
2215+
2216+
appTmpDownload: 'Fail muat turun sementara aplikasi',
22152217
},
22162218
app: {
22172219
app: 'Aplikasi | Aplikasi',

frontend/src/lang/modules/pt-br.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,8 @@ const message = {
22062206
dockerHelper: 'Arquivos como contêineres, imagens, volumes, cache de compilação, etc.',
22072207
volumes: 'Volumes',
22082208
buildCache: 'Cache de construção do container',
2209+
2210+
appTmpDownload: 'Arquivo de download temporário do aplicativo',
22092211
},
22102212
app: {
22112213
app: 'Aplicativo | Aplicativos',

frontend/src/lang/modules/ru.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,8 @@ const message = {
22012201
dockerHelper: 'Файлы, такие как контейнеры, образы, тома, кэш сборки и т.д.',
22022202
volumes: 'Тома',
22032203
buildCache: 'Кэш сборки контейнеров',
2204+
2205+
appTmpDownload: 'Временный файл загрузки приложения',
22042206
},
22052207
app: {
22062208
app: 'Приложение | Приложения',

frontend/src/lang/modules/tr.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,8 @@ const message = {
22582258
dockerHelper: 'Konteynerler, görüntüler, hacimler, derleme önbelleği vb. dosyalar',
22592259
volumes: 'Birimler',
22602260
buildCache: 'Konteyner Oluşturma Önbelleği',
2261+
2262+
appTmpDownload: 'Uygulama geçici indirme dosyası',
22612263
},
22622264
app: {
22632265
app: 'Uygulama | Uygulamalar',

frontend/src/lang/modules/zh-Hant.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,8 @@ const message = {
20822082
dockerHelper: '容器、映像、儲存卷、建置快取等檔案',
20832083
volumes: '磁碟區',
20842084
buildCache: '容器建置快取',
2085+
2086+
appTmpDownload: '應用程式暫存下載檔案',
20852087
},
20862088
app: {
20872089
app: '應用',

0 commit comments

Comments
 (0)