mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-24 22:51:19 +08:00
feat: 文件权限增加修改子文件功能 (#811)
This commit is contained in:
parent
8947e00302
commit
680f48dcba
6 changed files with 18 additions and 10 deletions
|
|
@ -22,6 +22,7 @@ type FileCreate struct {
|
||||||
IsLink bool `json:"isLink"`
|
IsLink bool `json:"isLink"`
|
||||||
IsSymlink bool `json:"isSymlink"`
|
IsSymlink bool `json:"isSymlink"`
|
||||||
LinkPath string `json:"linkPath"`
|
LinkPath string `json:"linkPath"`
|
||||||
|
Sub bool `json:"sub"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileDelete struct {
|
type FileDelete struct {
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,11 @@ func (f *FileService) BatchDelete(op request.FileBatchDelete) error {
|
||||||
|
|
||||||
func (f *FileService) ChangeMode(op request.FileCreate) error {
|
func (f *FileService) ChangeMode(op request.FileCreate) error {
|
||||||
fo := files.NewFileOp()
|
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 {
|
func (f *FileService) ChangeOwner(req request.FileRoleUpdate) error {
|
||||||
|
|
|
||||||
|
|
@ -91,11 +91,6 @@ func Execf(cmdStr string, a ...interface{}) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasNoPasswordSudo() bool {
|
func HasNoPasswordSudo() bool {
|
||||||
cmd := exec.Command("sudo", "-v")
|
|
||||||
err := cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
cmd2 := exec.Command("sudo", "-n", "ls")
|
cmd2 := exec.Command("sudo", "-n", "ls")
|
||||||
err2 := cmd2.Run()
|
err2 := cmd2.Run()
|
||||||
return err2 == nil
|
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 {
|
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 {
|
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, err := cmd.ExecWithTimeOut(cmdStr, 2*time.Second); err != nil {
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
|
|
@ -134,8 +137,8 @@ func (f FileOp) ChownR(dst string, uid string, gid string, sub bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FileOp) ChmodR(dst string, mode fs.FileMode) error {
|
func (f FileOp) ChmodR(dst string, mode int64) error {
|
||||||
cmdStr := fmt.Sprintf("chmod -R %v %s", mode, dst)
|
cmdStr := fmt.Sprintf("chmod -R %v %s", fmt.Sprintf("%04o", mode), dst)
|
||||||
if cmd.HasNoPasswordSudo() {
|
if cmd.HasNoPasswordSudo() {
|
||||||
cmdStr = fmt.Sprintf("sudo %s", cmdStr)
|
cmdStr = fmt.Sprintf("sudo %s", cmdStr)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ export namespace File {
|
||||||
isLink?: boolean;
|
isLink?: boolean;
|
||||||
isSymlink?: boolean;
|
isSymlink?: boolean;
|
||||||
linkPath?: boolean;
|
linkPath?: boolean;
|
||||||
|
sub?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileDelete {
|
export interface FileDelete {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="22" :offset="1">
|
<el-col :span="22" :offset="1">
|
||||||
<FileRole v-loading="loading" :mode="mode" @get-mode="getMode"></FileRole>
|
<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-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
|
@ -43,6 +46,7 @@ const acceptParams = (create: File.FileCreate) => {
|
||||||
form.value.isDir = create.isDir;
|
form.value.isDir = create.isDir;
|
||||||
form.value.path = create.path;
|
form.value.path = create.path;
|
||||||
form.value.isLink = false;
|
form.value.isLink = false;
|
||||||
|
form.value.sub = false;
|
||||||
|
|
||||||
mode.value = String(create.mode);
|
mode.value = String(create.mode);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue