mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-11-30 10:58:05 +08:00
feat: 文件权限增加修改子文件功能 (#811)
This commit is contained in:
parent
8947e00302
commit
680f48dcba
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ export namespace File {
|
||||
isLink?: boolean;
|
||||
isSymlink?: boolean;
|
||||
linkPath?: boolean;
|
||||
sub?: boolean;
|
||||
}
|
||||
|
||||
export interface FileDelete {
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user