1
0
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:
zhengkunwang 2024-04-18 22:40:07 +08:00 committed by GitHub
parent bb02991b05
commit b7c3dc0d2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 9 deletions

View File

@ -133,7 +133,7 @@ func (f *FileService) Create(op request.FileCreate) error {
} }
} }
if op.IsDir { if op.IsDir {
return fo.CreateDir(op.Path, fs.FileMode(mode)) return fo.CreateDirWithMode(op.Path, fs.FileMode(mode))
} }
if op.IsLink { if op.IsLink {
if !fo.Stat(op.LinkPath) { if !fo.Stat(op.LinkPath) {

View File

@ -54,17 +54,14 @@ func (f FileOp) GetContent(dst string) ([]byte, error) {
} }
func (f FileOp) CreateDir(dst string, mode fs.FileMode) 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 { if err := f.Fs.MkdirAll(dst, mode); err != nil {
return err return err
} }
modStr := fmt.Sprintf("%o", mode) return f.ChmodRWithMode(dst, mode, true)
modeInt, err := strconv.ParseInt(modStr, 10, 64)
if err != nil {
modeInt = 0755
}
return f.ChmodR(dst, modeInt, true)
} }
func (f FileOp) CreateFile(dst string) error { func (f FileOp) CreateFile(dst string) error {
@ -193,6 +190,23 @@ func (f FileOp) ChmodR(dst string, mode int64, sub bool) error {
return nil 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 { func (f FileOp) Rename(oldName string, newName string) error {
return f.Fs.Rename(oldName, newName) return f.Fs.Rename(oldName, newName)
} }