feat: 文件权限增加修改子文件功能 (#811)

This commit is contained in:
zhengkunwang223 2023-04-27 13:54:15 +08:00 committed by GitHub
parent 8947e00302
commit 680f48dcba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 10 deletions

View File

@ -22,6 +22,7 @@ type FileCreate struct {
IsLink bool `json:"isLink"`
IsSymlink bool `json:"isSymlink"`
LinkPath string `json:"linkPath"`
Sub bool `json:"sub"`
}
type FileDelete struct {

View File

@ -160,7 +160,11 @@ func (f *FileService) BatchDelete(op request.FileBatchDelete) error {
func (f *FileService) ChangeMode(op request.FileCreate) error {
fo := files.NewFileOp()
return fo.Chmod(op.Path, fs.FileMode(op.Mode))
if op.Sub {
return fo.ChmodR(op.Path, op.Mode)
} else {
return fo.Chmod(op.Path, fs.FileMode(op.Mode))
}
}
func (f *FileService) ChangeOwner(req request.FileRoleUpdate) error {

View File

@ -91,11 +91,6 @@ func Execf(cmdStr string, a ...interface{}) (string, error) {
}
func HasNoPasswordSudo() bool {
cmd := exec.Command("sudo", "-v")
err := cmd.Run()
if err != nil {
return false
}
cmd2 := exec.Command("sudo", "-n", "ls")
err2 := cmd2.Run()
return err2 == nil

View File

@ -121,9 +121,12 @@ func (f FileOp) Chown(dst string, uid int, gid int) error {
}
func (f FileOp) ChownR(dst string, uid string, gid string, sub bool) error {
cmdStr := fmt.Sprintf("sudo chown %s:%s %s", uid, gid, dst)
cmdStr := fmt.Sprintf("chown %s:%s %s", uid, gid, dst)
if sub {
cmdStr = fmt.Sprintf("sudo chown -R %s:%s %s", uid, gid, dst)
cmdStr = fmt.Sprintf("chown -R %s:%s %s", uid, gid, dst)
}
if cmd.HasNoPasswordSudo() {
cmdStr = fmt.Sprintf("sudo %s", cmdStr)
}
if msg, err := cmd.ExecWithTimeOut(cmdStr, 2*time.Second); err != nil {
if msg != "" {
@ -134,8 +137,8 @@ func (f FileOp) ChownR(dst string, uid string, gid string, sub bool) error {
return nil
}
func (f FileOp) ChmodR(dst string, mode fs.FileMode) error {
cmdStr := fmt.Sprintf("chmod -R %v %s", mode, dst)
func (f FileOp) ChmodR(dst string, mode int64) error {
cmdStr := fmt.Sprintf("chmod -R %v %s", fmt.Sprintf("%04o", mode), dst)
if cmd.HasNoPasswordSudo() {
cmdStr = fmt.Sprintf("sudo %s", cmdStr)
}

View File

@ -54,6 +54,7 @@ export namespace File {
isLink?: boolean;
isSymlink?: boolean;
linkPath?: boolean;
sub?: boolean;
}
export interface FileDelete {

View File

@ -7,6 +7,9 @@
<el-row>
<el-col :span="22" :offset="1">
<FileRole v-loading="loading" :mode="mode" @get-mode="getMode"></FileRole>
<el-form-item v-if="form.isDir">
<el-checkbox v-model="form.sub">{{ $t('file.containSub') }}</el-checkbox>
</el-form-item>
</el-col>
</el-row>
<template #footer>
@ -43,6 +46,7 @@ const acceptParams = (create: File.FileCreate) => {
form.value.isDir = create.isDir;
form.value.path = create.path;
form.value.isLink = false;
form.value.sub = false;
mode.value = String(create.mode);
};