mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-12 05:15:59 +08:00
fix(app): fix issue with sync custom-app failed (#8246)
This commit is contained in:
parent
11349642da
commit
0425cdcbb3
2 changed files with 24 additions and 25 deletions
|
|
@ -1816,19 +1816,13 @@ func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, e
|
||||||
func (w WebsiteService) UpdateProxyFile(req request.NginxProxyUpdate) (err error) {
|
func (w WebsiteService) UpdateProxyFile(req request.NginxProxyUpdate) (err error) {
|
||||||
var (
|
var (
|
||||||
website model.Website
|
website model.Website
|
||||||
nginxFull dto.NginxFull
|
|
||||||
oldRewriteContent []byte
|
oldRewriteContent []byte
|
||||||
)
|
)
|
||||||
website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
|
website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nginxFull, err = getNginxFull(&website)
|
absolutePath := fmt.Sprintf("%s/%s.conf", GetSitePath(website, SiteProxyDir), req.Name)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
includePath := fmt.Sprintf("%s/%s.conf", GetSitePath(website, SiteProxyDir), req.Name)
|
|
||||||
absolutePath := path.Join(nginxFull.Install.GetPath(), includePath)
|
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
oldRewriteContent, err = fileOp.GetContent(absolutePath)
|
oldRewriteContent, err = fileOp.GetContent(absolutePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -798,33 +798,38 @@ func (f FileOp) TarGzExtractPro(src, dst string, secret string) error {
|
||||||
}
|
}
|
||||||
return cmd.ExecCmdWithDir(commands, dst)
|
return cmd.ExecCmdWithDir(commands, dst)
|
||||||
}
|
}
|
||||||
|
func CopyCustomAppFile(srcPath, dstPath string) error {
|
||||||
|
if _, err := os.Stat(srcPath); os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("source file does not exist: %s", srcPath)
|
||||||
|
}
|
||||||
|
|
||||||
func CopyFileWithName(src, dst string, withName bool) error {
|
destDir := path.Dir(dstPath)
|
||||||
source, err := os.Open(src)
|
if err := os.MkdirAll(destDir, 0755); err != nil {
|
||||||
|
return fmt.Errorf("failed to create destination directory %s: %v", destDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
source, err := os.Open(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to open source file %s: %v", srcPath, err)
|
||||||
}
|
}
|
||||||
defer source.Close()
|
defer source.Close()
|
||||||
|
|
||||||
if path.Base(src) != path.Base(dst) && !withName {
|
tempFile, err := os.CreateTemp(destDir, "temp_*.tar.gz")
|
||||||
dst = path.Join(dst, path.Base(src))
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(path.Dir(dst)); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
_ = os.MkdirAll(path.Dir(dst), os.ModePerm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
target, err := os.OpenFile(dst+"_temp", os.O_RDWR|os.O_CREATE|os.O_TRUNC, constant.FilePerm)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to create temporary file in %s: %v", destDir, err)
|
||||||
}
|
}
|
||||||
defer target.Close()
|
defer os.Remove(tempFile.Name())
|
||||||
|
defer tempFile.Close()
|
||||||
|
|
||||||
if _, err = io.Copy(target, source); err != nil {
|
if _, err = io.Copy(tempFile, source); err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to copy file contents: %v", err)
|
||||||
}
|
}
|
||||||
if err = os.Rename(dst+"_temp", dst); err != nil {
|
|
||||||
return err
|
tempFile.Close()
|
||||||
|
source.Close()
|
||||||
|
|
||||||
|
if err = os.Rename(tempFile.Name(), dstPath); err != nil {
|
||||||
|
return fmt.Errorf("failed to rename temporary file to %s: %v", dstPath, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue