@@ -49,6 +49,7 @@ func (u *DeviceService) Scan() dto.CleanData {
4949 Size : uint64 (originalSize ),
5050 IsCheck : originalSize > 0 ,
5151 IsRecommend : true ,
52+ CanDelete : false ,
5253 Type : "1panel_original" ,
5354 Children : loadTreeWithDir (true , "1panel_original" , originalPath , fileOp ),
5455 })
@@ -68,6 +69,7 @@ func (u *DeviceService) Scan() dto.CleanData {
6869 Size : rollbackSize ,
6970 IsCheck : rollbackSize > 0 ,
7071 IsRecommend : true ,
72+ CanDelete : false ,
7173 Type : "rollback" ,
7274 Children : rollBackTree ,
7375 })
@@ -105,11 +107,7 @@ func (u *DeviceService) Clean(req []dto.Clean) {
105107 case "tmp_backup" :
106108 dropFileOrDir (path .Join (global .Dir .LocalBackupDir , "tmp" ))
107109 case "unknown_backup" :
108- if strings .HasPrefix (item .Name , path .Join (global .Dir .LocalBackupDir , "log/website" )) {
109- dropFileOrDir (item .Name )
110- } else {
111- dropFile (item .Name )
112- }
110+ dropFileOrDir (item .Name )
113111
114112 case "rollback" :
115113 dropFileOrDir (path .Join (global .Dir .BaseDir , rollbackPath , "app" ))
@@ -269,6 +267,7 @@ func loadUpgradeTree(fileOp fileUtils.FileOp) dto.CleanTree {
269267 Size : uint64 (upgradeSize ),
270268 IsCheck : false ,
271269 IsRecommend : true ,
270+ CanDelete : false ,
272271 Type : "upgrade" ,
273272 Children : loadTreeWithDir (true , "upgrade" , upgradePath , fileOp ),
274273 }
@@ -302,6 +301,7 @@ func loadAgentPackage(fileOp fileUtils.FileOp) dto.CleanTree {
302301 Label : "agent_packages" ,
303302 IsCheck : false ,
304303 IsRecommend : true ,
304+ CanDelete : false ,
305305 Type : "agent" ,
306306 }
307307 files , _ := os .ReadDir (pathItem )
@@ -316,6 +316,7 @@ func loadAgentPackage(fileOp fileUtils.FileOp) dto.CleanTree {
316316 Size : uint64 (itemSize ),
317317 IsCheck : true ,
318318 IsRecommend : true ,
319+ CanDelete : true ,
319320 Type : "agent" ,
320321 })
321322 } else {
@@ -333,6 +334,7 @@ func loadAgentPackage(fileOp fileUtils.FileOp) dto.CleanTree {
333334 Size : uint64 (itemSize .Size ()),
334335 IsCheck : ! isCurrentVersion ,
335336 IsRecommend : true ,
337+ CanDelete : true ,
336338 Type : "agent" ,
337339 })
338340 }
@@ -353,6 +355,7 @@ func loadBackupTree(fileOp fileUtils.FileOp) []dto.CleanTree {
353355 Size : uint64 (tmpSize ),
354356 IsCheck : tmpSize != 0 ,
355357 IsRecommend : true ,
358+ CanDelete : true ,
356359 Type : "tmp_backup" ,
357360 })
358361 backupRecords , _ := backupRepo .ListRecord ()
@@ -391,6 +394,7 @@ func loadUnknownApps(fileOp fileUtils.FileOp, recordMap map[string][]string) dto
391394 Label : "unknown_app" ,
392395 IsCheck : false ,
393396 IsRecommend : false ,
397+ CanDelete : false ,
394398 Name : backupPath ,
395399 Type : "unknown_backup" ,
396400 }
@@ -419,6 +423,7 @@ func loadUnknownDbs(fileOp fileUtils.FileOp, recordMap map[string][]string) dto.
419423 Name : backupPath ,
420424 IsCheck : false ,
421425 IsRecommend : false ,
426+ CanDelete : false ,
422427 Type : "unknown_backup" ,
423428 }
424429 _ = loadFileOrDirWithExclude (fileOp , 0 , backupPath , & treeData , excludePaths )
@@ -442,6 +447,7 @@ func loadUnknownWebsites(fileOp fileUtils.FileOp, recordMap map[string][]string)
442447 Name : backupPath ,
443448 IsCheck : false ,
444449 IsRecommend : false ,
450+ CanDelete : false ,
445451 Type : "unknown_backup" ,
446452 }
447453 _ = loadFileOrDirWithExclude (fileOp , 0 , backupPath , & treeData , excludePaths )
@@ -460,6 +466,7 @@ func loadUnknownSnapshot(fileOp fileUtils.FileOp) dto.CleanTree {
460466 Name : backupPath ,
461467 IsCheck : false ,
462468 IsRecommend : false ,
469+ CanDelete : false ,
463470 Type : "unknown_backup" ,
464471 }
465472 entries , _ := os .ReadDir (backupPath )
@@ -473,6 +480,7 @@ func loadUnknownSnapshot(fileOp fileUtils.FileOp) dto.CleanTree {
473480 Label : entry .Name (),
474481 IsCheck : false ,
475482 IsRecommend : false ,
483+ CanDelete : true ,
476484 Name : childPath ,
477485 Type : "unknown_backup" ,
478486 }
@@ -499,6 +507,7 @@ func loadUnknownWebsiteLog(fileOp fileUtils.FileOp) dto.CleanTree {
499507 Label : "unknown_website_log" ,
500508 IsCheck : false ,
501509 IsRecommend : true ,
510+ CanDelete : false ,
502511 Type : "unknown_backup" ,
503512 }
504513 dir := path .Join (global .Dir .LocalBackupDir , "log/website" )
@@ -522,6 +531,7 @@ func loadUnknownWebsiteLog(fileOp fileUtils.FileOp) dto.CleanTree {
522531 Label : dirName ,
523532 IsCheck : true ,
524533 IsRecommend : true ,
534+ CanDelete : true ,
525535 Name : dirPath ,
526536 Type : "unknown_backup" ,
527537 Size : uint64 (itemSize ),
@@ -552,6 +562,7 @@ func loadFileOrDirWithExclude(fileOp fileUtils.FileOp, index uint, dir string, r
552562 Label : entry .Name (),
553563 IsCheck : false ,
554564 IsRecommend : false ,
565+ CanDelete : true ,
555566 Name : childPath ,
556567 Type : "unknown_backup" ,
557568 }
@@ -564,18 +575,19 @@ func loadFileOrDirWithExclude(fileOp fileUtils.FileOp, index uint, dir string, r
564575 for _ , child := range childNode .Children {
565576 childNode .Size += child .Size
566577 }
567- rootTree .Size += childNode .Size
568578 } else {
569579 itemSize , _ := fileOp .GetDirSize (childPath )
570580 childNode .Size = uint64 (itemSize )
571- rootTree .Size += childNode .Size
581+ }
582+ if childNode .Size == 0 {
583+ continue
572584 }
573585 } else {
574586 info , _ := entry .Info ()
575587 childNode .Size = uint64 (info .Size ())
576- rootTree .Size += childNode .Size
577588 }
578589
590+ rootTree .Size += childNode .Size
579591 rootTree .Children = append (rootTree .Children , childNode )
580592 }
581593 return nil
@@ -633,6 +645,7 @@ func loadDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
633645 Label : "app_tmp_download" ,
634646 IsCheck : true ,
635647 IsRecommend : true ,
648+ CanDelete : false ,
636649 Type : "app_tmp_download" ,
637650 Name : "apps" ,
638651 }
@@ -653,19 +666,19 @@ func loadLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
653666 for _ , file := range list1 {
654667 size += file .Size
655668 }
656- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "system_log" , Size : size , Children : list1 , Type : "system_log" , IsRecommend : true })
669+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "system_log" , Size : size , Children : list1 , Type : "system_log" , IsRecommend : true , CanDelete : false })
657670
658671 path2 := path .Join (global .Dir .TaskDir )
659672 list2 := loadTreeWithDir (false , "task_log" , path2 , fileOp )
660673 size2 , _ := fileOp .GetDirSize (path2 )
661- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "task_log" , Size : uint64 (size2 ), Children : list2 , Type : "task_log" })
674+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "task_log" , Size : uint64 (size2 ), Children : list2 , Type : "task_log" , CanDelete : false })
662675
663676 websiteLogList := loadWebsiteLogTree (fileOp )
664677 logTotalSize := uint64 (0 )
665678 for _ , websiteLog := range websiteLogList {
666679 logTotalSize += websiteLog .Size
667680 }
668- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "website_log" , Size : logTotalSize , Children : websiteLogList , Type : "website_log" , IsRecommend : false })
681+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "website_log" , Size : logTotalSize , Children : websiteLogList , Type : "website_log" , IsRecommend : false , CanDelete : false })
669682
670683 return treeData
671684}
@@ -679,11 +692,12 @@ func loadWebsiteLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
679692 for _ , website := range websites {
680693 size3 , _ := fileOp .GetDirSize (path .Join (GetSiteDir (website .Alias ), "log" ))
681694 res = append (res , dto.CleanTree {
682- ID : uuid .NewString (),
683- Label : website .PrimaryDomain ,
684- Size : uint64 (size3 ),
685- Type : "website_log" ,
686- Name : website .Alias ,
695+ ID : uuid .NewString (),
696+ Label : website .PrimaryDomain ,
697+ Size : uint64 (size3 ),
698+ Type : "website_log" ,
699+ Name : website .Alias ,
700+ CanDelete : true ,
687701 })
688702 }
689703 return res
@@ -733,6 +747,7 @@ func loadAppTmpDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
733747 appTree .Name = appKey
734748 appTree .IsRecommend = true
735749 appTree .IsCheck = true
750+ appTree .CanDelete = false
736751 for _ , version := range missingVersions {
737752 versionPath := filepath .Join (appPath , version )
738753 size , _ := fileOp .GetDirSize (versionPath )
@@ -743,6 +758,7 @@ func loadAppTmpDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
743758 Size : uint64 (size ),
744759 IsCheck : true ,
745760 IsRecommend : true ,
761+ CanDelete : true ,
746762 Type : "app_tmp_download_version" ,
747763 Name : path .Join (appKey , version ),
748764 })
@@ -770,31 +786,31 @@ func loadContainerTree() []dto.CleanTree {
770786 imageSize += uint64 (file .Size )
771787 }
772788 }
773- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "container_images" , Size : imageSize , Children : nil , Type : "images" , IsRecommend : true })
789+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "container_images" , Size : imageSize , Children : nil , Type : "images" , IsRecommend : true , CanDelete : true })
774790
775791 containerSize := uint64 (0 )
776792 for _ , file := range diskUsage .Containers {
777793 if file .State != "running" {
778794 containerSize += uint64 (file .SizeRw )
779795 }
780796 }
781- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "container_containers" , Size : containerSize , Children : nil , Type : "containers" , IsRecommend : true })
797+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "container_containers" , Size : containerSize , Children : nil , Type : "containers" , IsRecommend : true , CanDelete : true })
782798
783799 volumeSize := uint64 (0 )
784800 for _ , file := range diskUsage .Volumes {
785801 if file .UsageData .RefCount <= 0 {
786802 volumeSize += uint64 (file .UsageData .Size )
787803 }
788804 }
789- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "container_volumes" , Size : volumeSize , IsCheck : volumeSize > 0 , Children : nil , Type : "volumes" , IsRecommend : true })
805+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "container_volumes" , Size : volumeSize , IsCheck : volumeSize > 0 , Children : nil , Type : "volumes" , IsRecommend : true , CanDelete : true })
790806
791807 var buildCacheTotalSize int64
792808 for _ , cache := range diskUsage .BuildCache {
793809 if cache .Type == "source.local" {
794810 buildCacheTotalSize += cache .Size
795811 }
796812 }
797- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "build_cache" , Size : uint64 (buildCacheTotalSize ), IsCheck : buildCacheTotalSize > 0 , Type : "build_cache" , IsRecommend : true })
813+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : "build_cache" , Size : uint64 (buildCacheTotalSize ), IsCheck : buildCacheTotalSize > 0 , Type : "build_cache" , IsRecommend : true , CanDelete : true })
798814 return treeData
799815}
800816
@@ -804,7 +820,7 @@ func loadTreeWithCheck(treeData []dto.CleanTree, pathItem, treeType string, file
804820 return treeData
805821 }
806822 list := loadTreeWithAllFile (true , pathItem , treeType , pathItem , fileOp )
807- treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : treeType , Size : uint64 (size ), IsCheck : size > 0 , Children : list , Type : treeType , IsRecommend : true })
823+ treeData = append (treeData , dto.CleanTree {ID : uuid .NewString (), Label : treeType , Size : uint64 (size ), IsCheck : size > 0 , Children : list , Type : treeType , IsRecommend : true , CanDelete : false })
808824 return treeData
809825}
810826
@@ -831,6 +847,7 @@ func loadTreeWithDir(isCheck bool, treeType, pathItem string, fileOp fileUtils.F
831847 Name : strings .TrimPrefix (file .Name (), "/" ),
832848 IsCheck : isCheck ,
833849 IsRecommend : isCheck ,
850+ CanDelete : true ,
834851 }
835852 lists = append (lists , item )
836853 }
@@ -878,6 +895,7 @@ func loadTreeWithAllFile(isCheck bool, originalPath, treeType, pathItem string,
878895 Name : name ,
879896 IsCheck : isCheck ,
880897 IsRecommend : isCheck ,
898+ CanDelete : true ,
881899 }
882900 if file .IsDir () {
883901 item .Children = loadTreeWithAllFile (isCheck , originalPath , treeType , path .Join (pathItem , file .Name ()), fileOp )
0 commit comments