mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-10-31 03:07:34 +08:00 
			
		
		
		
	fix: 解决复制文件到文件夹报错的BUG
This commit is contained in:
		
							parent
							
								
									71d90aca59
								
							
						
					
					
						commit
						4307673f7b
					
				
					 7 changed files with 42 additions and 19 deletions
				
			
		|  | @ -2,6 +2,7 @@ package helper | |||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"github.com/1Panel-dev/1Panel/backend/buserr" | ||||
| 	"net/http" | ||||
| 	"strconv" | ||||
| 
 | ||||
|  | @ -51,6 +52,8 @@ func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) { | |||
| 			res.Msg = i18n.GetMsgWithMap("ErrAuth", map[string]interface{}{"detail": err}) | ||||
| 		case errors.Is(constant.ErrInitialPassword, err): | ||||
| 			res.Msg = i18n.GetMsgWithMap("ErrInitialPassword", map[string]interface{}{"detail": err}) | ||||
| 		case errors.As(err, &buserr.BusinessError{}): | ||||
| 			res.Msg = err.Error() | ||||
| 		default: | ||||
| 			res.Msg = i18n.GetMsgWithMap(msgKey, map[string]interface{}{"detail": err}) | ||||
| 		} | ||||
|  |  | |||
|  | @ -142,7 +142,7 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int | |||
| 
 | ||||
| 	list, _ := appInstallRepo.GetBy(commonRepo.WithByName(name)) | ||||
| 	if len(list) > 0 { | ||||
| 		return nil, buserr.New(constant.ErrNameIsExist, "", nil) | ||||
| 		return nil, buserr.New(constant.ErrNameIsExist) | ||||
| 	} | ||||
| 
 | ||||
| 	httpPort, err := checkPort("PANEL_APP_PORT_HTTP", params) | ||||
|  |  | |||
|  | @ -89,7 +89,7 @@ func checkPort(key string, params map[string]interface{}) (int, error) { | |||
| 	if ok { | ||||
| 		portN := int(math.Ceil(port.(float64))) | ||||
| 		if common.ScanPort(portN) { | ||||
| 			return portN, buserr.New(constant.ErrPortInUsed, portN, nil) | ||||
| 			return portN, buserr.WithMessage(constant.ErrPortInUsed, portN, nil) | ||||
| 		} else { | ||||
| 			return portN, nil | ||||
| 		} | ||||
|  | @ -378,7 +378,7 @@ func checkLimit(app model.App) error { | |||
| 			return err | ||||
| 		} | ||||
| 		if len(installs) >= app.Limit { | ||||
| 			return buserr.New(constant.ErrAppLimit, "", nil) | ||||
| 			return buserr.New(constant.ErrAppLimit) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
|  | @ -414,7 +414,7 @@ func checkRequiredAndLimit(app model.App) error { | |||
| 
 | ||||
| 			_, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds)) | ||||
| 			if err != nil { | ||||
| 				return buserr.New(constant.ErrAppRequired, requireApp.Name, nil) | ||||
| 				return buserr.WithMessage(constant.ErrAppRequired, requireApp.Name, nil) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | @ -439,6 +439,7 @@ func copyAppData(key, version, installName string, params map[string]interface{} | |||
| 	fileOp := files.NewFileOp() | ||||
| 	resourceDir := path.Join(constant.AppResourceDir, key, "versions", version) | ||||
| 	installAppDir := path.Join(constant.AppInstallDir, key) | ||||
| 
 | ||||
| 	if !fileOp.Stat(installAppDir) { | ||||
| 		if err = fileOp.CreateDir(installAppDir, 0755); err != nil { | ||||
| 			return | ||||
|  | @ -450,7 +451,11 @@ func copyAppData(key, version, installName string, params map[string]interface{} | |||
| 			return | ||||
| 		} | ||||
| 	} | ||||
| 	if err = fileOp.Copy(resourceDir, appDir); err != nil { | ||||
| 	if err = fileOp.Copy(resourceDir, installAppDir); err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	versionDir := path.Join(installAppDir, version) | ||||
| 	if err = fileOp.Rename(versionDir, appDir); err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	envPath := path.Join(appDir, ".env") | ||||
|  |  | |||
|  | @ -13,7 +13,12 @@ type BusinessError struct { | |||
| 
 | ||||
| func (e BusinessError) Error() string { | ||||
| 
 | ||||
| 	content := i18n.GetErrMsg(e.Msg, map[string]interface{}{"detail": e.Detail}) | ||||
| 	content := "" | ||||
| 	if e.Detail != nil { | ||||
| 		content = i18n.GetErrMsg(e.Msg, map[string]interface{}{"detail": e.Detail}) | ||||
| 	} else { | ||||
| 		content = i18n.GetErrMsg(e.Msg, nil) | ||||
| 	} | ||||
| 	if content == "" { | ||||
| 		if e.Err != nil { | ||||
| 			return e.Err.Error() | ||||
|  | @ -23,7 +28,15 @@ func (e BusinessError) Error() string { | |||
| 	return content | ||||
| } | ||||
| 
 | ||||
| func New(Key string, detail interface{}, err error) BusinessError { | ||||
| func New(Key string) BusinessError { | ||||
| 	return BusinessError{ | ||||
| 		Msg:    Key, | ||||
| 		Detail: nil, | ||||
| 		Err:    nil, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func WithMessage(Key string, detail interface{}, err error) BusinessError { | ||||
| 	return BusinessError{ | ||||
| 		Msg:    Key, | ||||
| 		Detail: detail, | ||||
|  |  | |||
|  | @ -231,8 +231,8 @@ func (f FileOp) CopyDir(src, dst string) error { | |||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	//dstDir := filepath.Join(dst, srcInfo.Name()) | ||||
| 	if err := f.Fs.MkdirAll(dst, srcInfo.Mode()); err != nil { | ||||
| 	dstDir := filepath.Join(dst, srcInfo.Name()) | ||||
| 	if err := f.Fs.MkdirAll(dstDir, srcInfo.Mode()); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
|  | @ -245,15 +245,13 @@ func (f FileOp) CopyDir(src, dst string) error { | |||
| 
 | ||||
| 	for _, obj := range obs { | ||||
| 		fSrc := filepath.Join(src, obj.Name()) | ||||
| 		fDst := filepath.Join(dst, obj.Name()) | ||||
| 
 | ||||
| 		if obj.IsDir() { | ||||
| 			err = f.CopyDir(fSrc, fDst) | ||||
| 			err = f.CopyDir(fSrc, dstDir) | ||||
| 			if err != nil { | ||||
| 				errs = append(errs, err) | ||||
| 			} | ||||
| 		} else { | ||||
| 			err = f.CopyFile(fSrc, fDst) | ||||
| 			err = f.CopyFile(fSrc, dstDir) | ||||
| 			if err != nil { | ||||
| 				errs = append(errs, err) | ||||
| 			} | ||||
|  | @ -284,7 +282,12 @@ func (f FileOp) CopyFile(src, dst string) error { | |||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	dstFile, err := f.Fs.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775) | ||||
| 	srcInfo, err := f.Fs.Stat(src) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	dstFile, err := f.Fs.OpenFile(path.Join(dst, srcInfo.Name()), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | @ -297,7 +300,7 @@ func (f FileOp) CopyFile(src, dst string) error { | |||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if err = f.Fs.Chmod(dst, info.Mode()); err != nil { | ||||
| 	if err = f.Fs.Chmod(dstFile.Name(), info.Mode()); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -171,13 +171,13 @@ func (f *FileInfo) getContent() error { | |||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		if detectBinary(cByte) { | ||||
| 			return buserr.New(constant.ErrFileCanNotRead, "", nil) | ||||
| 		if len(cByte) > 0 && detectBinary(cByte) { | ||||
| 			return buserr.New(constant.ErrFileCanNotRead) | ||||
| 		} | ||||
| 		f.Content = string(cByte) | ||||
| 		return nil | ||||
| 	} else { | ||||
| 		return buserr.New(constant.ErrFileToLarge, "", nil) | ||||
| 		return buserr.New(constant.ErrFileToLarge) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -90,7 +90,6 @@ const handleClose = () => { | |||
| }; | ||||
| 
 | ||||
| const getPath = (path: string) => { | ||||
|     console.log(path); | ||||
|     addForm.newPath = path; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue