mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 解决创建 PHP 网站首页无法访问的 BUG (#4577)
This commit is contained in:
parent
bb02991b05
commit
b7c3dc0d2a
@ -133,7 +133,7 @@ func (f *FileService) Create(op request.FileCreate) error {
|
||||
}
|
||||
}
|
||||
if op.IsDir {
|
||||
return fo.CreateDir(op.Path, fs.FileMode(mode))
|
||||
return fo.CreateDirWithMode(op.Path, fs.FileMode(mode))
|
||||
}
|
||||
if op.IsLink {
|
||||
if !fo.Stat(op.LinkPath) {
|
||||
|
@ -54,17 +54,14 @@ func (f FileOp) GetContent(dst string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (f FileOp) CreateDir(dst string, mode fs.FileMode) error {
|
||||
return f.Fs.MkdirAll(dst, mode)
|
||||
}
|
||||
|
||||
func (f FileOp) CreateDirWithMode(dst string, mode fs.FileMode) error {
|
||||
if err := f.Fs.MkdirAll(dst, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
modStr := fmt.Sprintf("%o", mode)
|
||||
|
||||
modeInt, err := strconv.ParseInt(modStr, 10, 64)
|
||||
if err != nil {
|
||||
modeInt = 0755
|
||||
}
|
||||
|
||||
return f.ChmodR(dst, modeInt, true)
|
||||
return f.ChmodRWithMode(dst, mode, true)
|
||||
}
|
||||
|
||||
func (f FileOp) CreateFile(dst string) error {
|
||||
@ -193,6 +190,23 @@ func (f FileOp) ChmodR(dst string, mode int64, sub bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f FileOp) ChmodRWithMode(dst string, mode fs.FileMode, sub bool) error {
|
||||
cmdStr := fmt.Sprintf(`chmod %v "%s"`, fmt.Sprintf("%o", mode.Perm()), dst)
|
||||
if sub {
|
||||
cmdStr = fmt.Sprintf(`chmod -R %v "%s"`, fmt.Sprintf("%o", mode.Perm()), dst)
|
||||
}
|
||||
if cmd.HasNoPasswordSudo() {
|
||||
cmdStr = fmt.Sprintf("sudo %s", cmdStr)
|
||||
}
|
||||
if msg, err := cmd.ExecWithTimeOut(cmdStr, 10*time.Second); err != nil {
|
||||
if msg != "" {
|
||||
return errors.New(msg)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f FileOp) Rename(oldName string, newName string) error {
|
||||
return f.Fs.Rename(oldName, newName)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user