Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions agent/app/service/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,25 @@ func (a *AppInstallService) Update(req request.AppInstalledUpdate) error {
go func() {
nginxInstall, err := getNginxFull(&website)
if err != nil {
global.LOG.Errorf(buserr.WithErr(constant.ErrUpdateBuWebsite, err).Error())
global.LOG.Error(buserr.WithErr(constant.ErrUpdateBuWebsite, err).Error())
return
}
config := nginxInstall.SiteConfig.Config
servers := config.FindServers()
if len(servers) == 0 {
global.LOG.Errorf(buserr.WithErr(constant.ErrUpdateBuWebsite, errors.New("nginx config is not valid")).Error())
global.LOG.Error(buserr.WithErr(constant.ErrUpdateBuWebsite, errors.New("nginx config is not valid")).Error())
return
}
server := servers[0]
proxy := fmt.Sprintf("http://127.0.0.1:%d", installed.HttpPort)
server.UpdateRootProxy([]string{proxy})

if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
global.LOG.Errorf(buserr.WithErr(constant.ErrUpdateBuWebsite, err).Error())
global.LOG.Error(buserr.WithErr(constant.ErrUpdateBuWebsite, err).Error())
return
}
if err := nginxCheckAndReload(nginxInstall.SiteConfig.OldContent, config.FilePath, nginxInstall.Install.ContainerName); err != nil {
global.LOG.Errorf(buserr.WithErr(constant.ErrUpdateBuWebsite, err).Error())
global.LOG.Error(buserr.WithErr(constant.ErrUpdateBuWebsite, err).Error())
return
}
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but you've shared a snippet of PHP code which isn't clear enough to analyze the differences between the two versions that you're contrasting it against your version. Could you please share more details on the current application context or additional information about the specific lines/diagrams being shown? That would help me accurately assess what parts need improvement or clarification.

Expand Down
16 changes: 16 additions & 0 deletions core/utils/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package files

import (
"bytes"
"crypto/md5"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -169,3 +171,17 @@ func Stat(path string) bool {
}
return true
}

func GetFileMD5(filePath string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()
hash := md5.New()

if _, err = io.Copy(hash, file); err != nil {
return "", err
}
return hex.EncodeToString(hash.Sum(nil)), nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The given code seems to be correct and there are no apparent issues. However, it's worth mentioning that the md5 function from the standard library is not recommended due to security concerns. It uses MD4 algorithm which was replaced by MD5 in version 4 of the specification but some programs do not support this old version anymore. Instead of using this library, you can opt for an alternative approach like third-party libraries such as "crypto/tls" with its built-in MD5 hashing functionality.

Additionally, consider refactoring your imports if necessary to ensure proper version compatibility and reduce clutter.

Here are some suggestions:

  1. Refactor imports (if needed)

  2. Use different hashing algorithms

  3. Implement proper type hints where appropriate

Remember that these changes would affect future code versions when merging new commits into production branches.

Loading