2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 06:47:20 +08:00

feat(文件): 优化chmod使用系统命令

This commit is contained in:
耗子
2024-05-23 20:27:09 +08:00
parent 5cd68fcdc3
commit b1ff8fff3d
4 changed files with 10 additions and 7 deletions

View File

@@ -20,7 +20,5 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
version: latest
args: --timeout=30m ./...

View File

@@ -34,7 +34,7 @@ archives:
- panel
format: zip
wrap_in_directory: false
strip_parent_binary_folder: true
strip_binary_directory: true
files:
- LICENSE
- docs/*

View File

@@ -353,7 +353,7 @@ func (r *FileController) Permission(ctx http.Context) http.Response {
return sanitize
}
if err := tools.Chmod(request.Path, os.FileMode(request.Mode)); err != nil {
if err := tools.Chmod(request.Path, request.Mode); err != nil {
return Error(ctx, http.StatusInternalServerError, err.Error())
}
if err := tools.Chown(request.Path, request.Owner, request.Group); err != nil {
@@ -523,6 +523,6 @@ func (r *FileController) List(ctx http.Context) http.Response {
// setPermission
func (r *FileController) setPermission(path string, mode uint, owner, group string) {
_ = tools.Chmod(path, os.FileMode(mode))
_ = tools.Chmod(path, mode)
_ = tools.Chown(path, owner, group)
}

View File

@@ -112,8 +112,13 @@ func Mkdir(path string, permission os.FileMode) error {
}
// Chmod 修改文件/目录权限
func Chmod(path string, permission os.FileMode) error {
return os.Chmod(path, permission)
func Chmod(path string, permission uint) error {
if env.IsWindows() {
return errors.New("chmod is not supported on Windows")
}
cmd := exec.Command("chmod", "-R", cast.ToString(permission), path)
return cmd.Run()
}
// Chown 修改文件或目录所有者