mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-10 04:16:29 +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) {
|
||||
var (
|
||||
website model.Website
|
||||
nginxFull dto.NginxFull
|
||||
oldRewriteContent []byte
|
||||
)
|
||||
website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nginxFull, err = getNginxFull(&website)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
includePath := fmt.Sprintf("%s/%s.conf", GetSitePath(website, SiteProxyDir), req.Name)
|
||||
absolutePath := path.Join(nginxFull.Install.GetPath(), includePath)
|
||||
absolutePath := fmt.Sprintf("%s/%s.conf", GetSitePath(website, SiteProxyDir), req.Name)
|
||||
fileOp := files.NewFileOp()
|
||||
oldRewriteContent, err = fileOp.GetContent(absolutePath)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -798,33 +798,38 @@ func (f FileOp) TarGzExtractPro(src, dst string, secret string) error {
|
|||
}
|
||||
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 {
|
||||
source, err := os.Open(src)
|
||||
destDir := path.Dir(dstPath)
|
||||
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 {
|
||||
return err
|
||||
return fmt.Errorf("failed to open source file %s: %v", srcPath, err)
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
if path.Base(src) != path.Base(dst) && !withName {
|
||||
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)
|
||||
tempFile, err := os.CreateTemp(destDir, "temp_*.tar.gz")
|
||||
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 {
|
||||
return err
|
||||
if _, err = io.Copy(tempFile, source); err != nil {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue