mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
fix: 解决网站设置用户/组报错的问题 (#710)
This commit is contained in:
parent
6cee4bfe7c
commit
a0b820649e
@ -1092,7 +1092,13 @@ func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermiss
|
|||||||
absoluteIndexPath = path.Join(absoluteIndexPath, website.SiteDir)
|
absoluteIndexPath = path.Join(absoluteIndexPath, website.SiteDir)
|
||||||
}
|
}
|
||||||
chownCmd := fmt.Sprintf("chown -R %s:%s %s", req.User, req.Group, absoluteIndexPath)
|
chownCmd := fmt.Sprintf("chown -R %s:%s %s", req.User, req.Group, absoluteIndexPath)
|
||||||
if _, err := cmd.ExecWithTimeOut(chownCmd, 1*time.Second); err != nil {
|
if cmd.HasNoPasswordSudo() {
|
||||||
|
chownCmd = fmt.Sprintf("sudo %s", chownCmd)
|
||||||
|
}
|
||||||
|
if out, err := cmd.ExecWithTimeOut(chownCmd, 1*time.Second); err != nil {
|
||||||
|
if out != "" {
|
||||||
|
return errors.New(out)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
website.User = req.User
|
website.User = req.User
|
||||||
|
@ -88,3 +88,14 @@ func Execf(cmdStr string, a ...interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
return stdout.String(), nil
|
return stdout.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user