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
13 changes: 10 additions & 3 deletions agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,17 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
}
req.Params["WEBSITE_DIR"] = siteDir
oldWebStePath, _ := settingRepo.GetValueByKey("WEBSITE_DIR")
if oldWebStePath != "" && oldWebStePath != siteDir {
_ = files.NewFileOp().Rename(oldWebStePath, siteDir)
fileOp := files.NewFileOp()
if oldWebStePath != "" && oldWebStePath != siteDir && fileOp.Stat(oldWebStePath) {
_ = fileOp.Rename(oldWebStePath, siteDir)
}
if !fileOp.Stat(siteDir) {
_ = fileOp.CreateDir(siteDir, constant.DirPerm)
}
err = settingRepo.UpdateOrCreate("WEBSITE_DIR", siteDir)
if err != nil {
return
}
_ = settingRepo.UpdateOrCreate("WEBSITE_DIR", siteDir)
}
}
for key := range req.Params {
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 doesn't contain any significant issues or suggestions for changes to be made from my perspective. There don't appear to be any irregularities detected. The provided function "Install" is attempting to set the value of "WEBSITE_DIR" variable according to a mapping specified in req.Params. It first verifies if oldWebStePath (the previous value saved on filesystem) matches the current one. If it does not match, then it calls a method named _. This seems like an implementation detail and doesn't seem to have a major impact here.

However, based on the context and purpose of this code being for installation purposes specifically into an existing project, there's probably more room for improvement regarding the handling of potential errors when saving/deleting files/filesystem operations. For instance:

  • Check if renaming old webste path works properly after file op stat/filename check; also add some error checking mechanism around rename/diff between filenames/states.
  • Consider using package constant/strings instead of hardcoded values like dir perm constants for better practices (especially since these might vary across different OSes).

This was just a brief summary - please note that you should double-check with the original team about specific use cases or additional requirements they may have.

Expand Down
8 changes: 3 additions & 5 deletions agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
golang.org/x/oauth2 v0.24.0
golang.org/x/sys v0.28.0
golang.org/x/text v0.21.0
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/gorm v1.25.11
Expand Down Expand Up @@ -124,9 +125,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/h2non/filetype v1.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down Expand Up @@ -219,8 +218,8 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand All @@ -233,7 +232,6 @@ require (
golang.org/x/term v0.27.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/grpc v1.67.1 // indirect
Expand Down
Loading
Loading