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

Function downloadApp

agent/app/service/app_utils.go:1018–1072  ·  view source on GitHub ↗
(app model.App, appDetail model.AppDetail, appInstall *model.AppInstall, logger *logrus.Logger)

Source from the content-addressed store, hash-verified

1016}
1017
1018func downloadApp(app model.App, appDetail model.AppDetail, appInstall *model.AppInstall, logger *logrus.Logger) (err error) {
1019 if app.IsLocalApp() || app.IsCustomApp() {
1020 return nil
1021 }
1022 appResourceDir := path.Join(global.Dir.AppResourceDir, app.Resource)
1023 appDownloadDir := app.GetAppResourcePath()
1024 appVersionDir := path.Join(appDownloadDir, appDetail.Version)
1025 fileOp := files.NewFileOp()
1026 if !appDetail.Update && fileOp.Stat(appVersionDir) {
1027 return
1028 }
1029 if !fileOp.Stat(appDownloadDir) {
1030 _ = fileOp.CreateDir(appDownloadDir, constant.DirPerm)
1031 }
1032 if !fileOp.Stat(appVersionDir) {
1033 _ = fileOp.CreateDir(appVersionDir, constant.DirPerm)
1034 }
1035 if logger == nil {
1036 global.LOG.Infof("download app [%s] from %s", app.Name, appDetail.DownloadUrl)
1037 } else {
1038 logger.Printf("download app [%s] from %s", app.Name, appDetail.DownloadUrl)
1039 }
1040
1041 filePath := path.Join(appVersionDir, app.Key+"-"+appDetail.Version+".tar.gz")
1042
1043 defer func() {
1044 if err != nil {
1045 if appInstall != nil {
1046 appInstall.Status = constant.StatusDownloadErr
1047 appInstall.Message = err.Error()
1048 }
1049 }
1050 }()
1051
1052 if err = files.DownloadFileWithProxy(appDetail.DownloadUrl, filePath); err != nil {
1053 if logger == nil {
1054 global.LOG.Errorf("download app [%s] error %v", app.Name, err)
1055 } else {
1056 logger.Printf("download app [%s] error %v", app.Name, err)
1057 }
1058 return
1059 }
1060 if err = fileOp.Decompress(context.Background(), filePath, appResourceDir, files.SdkTarGz, ""); err != nil {
1061 if logger == nil {
1062 global.LOG.Errorf("decompress app[%s] error %v", app.Name, err)
1063 } else {
1064 logger.Printf("decompress app[%s] error %v", app.Name, err)
1065 }
1066 return
1067 }
1068 _ = fileOp.DeleteFile(filePath)
1069 appDetail.Update = false
1070 _ = appDetailRepo.Update(context.Background(), appDetail)
1071 return
1072}
1073
1074func copyData(task *task.Task, app model.App, appDetail model.AppDetail, appInstall *model.AppInstall, req request.AppInstallCreate) (err error) {
1075 fileOp := files.NewFileOp()

Callers 5

upgradeInstallFunction · 0.85
copyDataFunction · 0.85
GetAppDetailMethod · 0.85
CreateMethod · 0.85
UpdateMethod · 0.85

Calls 9

StatMethod · 0.95
CreateDirMethod · 0.95
DecompressMethod · 0.95
DeleteFileMethod · 0.95
IsLocalAppMethod · 0.80
IsCustomAppMethod · 0.80
GetAppResourcePathMethod · 0.80
UpdateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected