-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: When creating files/folders, use the parent directory's user an… #8419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/1Panel-dev/1Panel/agent/app/repo" | ||
|
|
@@ -1357,3 +1358,17 @@ func ConfigAIProxy(website model.Website) error { | |
| } | ||
| return nil | ||
| } | ||
|
|
||
| func handleDefaultOwn(dir string) { | ||
| parentDir := path.Dir(dir) | ||
| info, err := os.Stat(parentDir) | ||
| if err != nil { | ||
| return | ||
| } | ||
| stat, ok := info.Sys().(*syscall.Stat_t) | ||
| uid, gid := -1, -1 | ||
| if ok { | ||
| uid, gid = int(stat.Uid), int(stat.Gid) | ||
| } | ||
| _ = os.Chown(dir, uid, gid) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code changes mostly focus on modifying how files are created during the A minor suggestion would be to include a return statement after calling |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,5 +78,5 @@ func (b *BaseApi) CleanLogs(c *gin.Context) { | |
| return | ||
| } | ||
|
|
||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,7 @@ func (b *BaseApi) GetTerminalSettingInfo(c *gin.Context) { | |
| // @Security Timestamp | ||
| // @Router /core/settings/search/available [get] | ||
| func (b *BaseApi) GetSystemAvailable(c *gin.Context) { | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -86,7 +86,7 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) { | |
| entranceValue := base64.StdEncoding.EncodeToString([]byte(req.Value)) | ||
| c.SetCookie("SecurityEntrance", entranceValue, 0, "", "", false, true) | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -108,7 +108,7 @@ func (b *BaseApi) UpdateTerminalSetting(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -139,7 +139,7 @@ func (b *BaseApi) UpdateProxy(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -161,7 +161,7 @@ func (b *BaseApi) UpdateMenu(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -183,7 +183,7 @@ func (b *BaseApi) UpdatePassword(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -205,7 +205,7 @@ func (b *BaseApi) UpdateSSL(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -274,7 +274,7 @@ func (b *BaseApi) UpdateBindInfo(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -296,7 +296,7 @@ func (b *BaseApi) UpdatePort(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -318,7 +318,7 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -380,7 +380,7 @@ func (b *BaseApi) MFABind(c *gin.Context) { | |
| return | ||
| } | ||
|
|
||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| func (b *BaseApi) ReloadSSL(c *gin.Context) { | ||
|
|
@@ -393,7 +393,7 @@ func (b *BaseApi) ReloadSSL(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| // @Tags System Setting | ||
|
|
@@ -442,7 +442,7 @@ func (b *BaseApi) UpdateApiConfig(c *gin.Context) { | |
| helper.InternalServer(c, err) | ||
| return | ||
| } | ||
| helper.SuccessWithOutData(c) | ||
| helper.Success(c) | ||
| } | ||
|
|
||
| func checkEntrancePattern(val string) bool { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided Go code changes seem generally well-structured, but there are a few minor issues and optimizations that could be addressed: Issues:
Optimizations:
Here’s an updated version with these improvements: package main
import (
"encoding/base64"
)
type BaseApi struct{}
func (b *BaseApi) GetTerminalSettingInfo(c *gin.Context) {
helper.SuccessWithOutData(c)
}
// @Security Timestamp
// @Router /core/settings/search/available [get]
func (b *BaseApi) GetSystemAvailable(c *gin.Context) {
helper.Success(c)
}
// Update setting information
func (b *BaseApi) UpdateSetting(c *gin.Context) error {
req := &updateReq{} // Assuming updateReq is defined elsewhere
if req.Value != "" {
valueBytes := base64.StdEncoding.EncodeToString([]byte(req.Value))
c.SetCookie("SecurityEntrance", valueBytes, 0, "", "", false, true)
}
return helper.Success(c)
}
// Update terminal setting
func (b *BaseApi) UpdateTerminalSetting(c *gin.Context) error {
var err error
// Your logic here...
return handlerSuccess(err)
}
// Update proxy settings
func (b *BaseApi) UpdateProxy(c *gin.Context) error {
err := handleInternalServer()
return handlerSuccess(err)
}
// Other handlers remain unchanged...
func handlerSuccess(err error) error {
if err != nil {
return helper.InternalServer(e)
}
return nil
}
// Check entrance pattern
func checkEntrancePattern(val string) bool {
// Implement your validation logic here
return false
}Explanation:
These changes should improve the maintainability and readability of the code. Make sure to review any dependent functions or modules as they may require adjustments as well. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several areas where the code could improve:
Return Type Consistency: The function
Createreturns an error type directly if an operation fails, but when it reaches the end of the method without returning an error, its return type does not match other methods. This inconsistency might be due to an oversight.Error Handling Clarity: When handling errors returned by certain operations within a conditional block, you're using early return statements (
return). However, for better clarity and consistency, consider whether you should have usedif err != nil { // handle error } else { continue; }.Duplication: There is repetition in some parts of the
Createmethod regarding how errors are handled after creating directories or files with specific modes. Consider refactoring this duplication into helper functions or variables for clarity.Here is a slightly improved version of the
Createmethod considering these points:Summary:
Createmust callreturn. If they do not, ensure consistent return types.