mirror of
https://github.com/acepanel/panel.git
synced 2026-02-05 00:39:32 +08:00
refactor: 重构 tools.Chmod 函数
This commit is contained in:
@@ -182,7 +182,9 @@ func (r *PureFtpdController) Add(ctx http.Context) http.Response {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "目录不存在")
|
||||
}
|
||||
|
||||
tools.Chmod(path, 0755)
|
||||
if err = tools.Chmod(path, 0755); err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "修改目录权限失败")
|
||||
}
|
||||
tools.Chown(path, "www", "www")
|
||||
tools.Exec(`yes '` + password + `' | pure-pw useradd ` + username + ` -u www -g www -d ` + path)
|
||||
tools.Exec("pure-pw mkdb")
|
||||
|
||||
@@ -123,7 +123,9 @@ func (r *ToolBoxController) SetSWAP(ctx http.Context) http.Response {
|
||||
} else {
|
||||
tools.Exec("dd if=/dev/zero of=/www/swap bs=1M count=" + cast.ToString(size))
|
||||
tools.Exec("mkswap -f /www/swap")
|
||||
tools.Chmod("/www/swap", 0600)
|
||||
if err := tools.Chmod("/www/swap", 0600); err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "设置 SWAP 权限失败")
|
||||
}
|
||||
}
|
||||
tools.Exec("swapon /www/swap")
|
||||
tools.Exec("echo '/www/swap swap swap defaults 0 0' >> /etc/fstab")
|
||||
|
||||
@@ -114,7 +114,9 @@ func (s *BackupImpl) WebsiteRestore(website models.Website, backupFile string) e
|
||||
|
||||
tools.Exec(`rm -rf '` + website.Path + `/*'`)
|
||||
tools.Exec(`unzip -o '` + backupFile + `' -d '` + website.Path + `' 2>&1`)
|
||||
tools.Chmod(website.Path, 0755)
|
||||
if err := tools.Chmod(website.Path, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
tools.Chown(website.Path, "www", "www")
|
||||
|
||||
return nil
|
||||
|
||||
@@ -282,8 +282,12 @@ server
|
||||
return models.Website{}, err
|
||||
}
|
||||
|
||||
tools.Chmod(r.setting.Get(models.SettingKeyWebsitePath), 0755)
|
||||
tools.Chmod(website.Path, 0755)
|
||||
if err := tools.Chmod(r.setting.Get(models.SettingKeyWebsitePath), 0755); err != nil {
|
||||
return models.Website{}, err
|
||||
}
|
||||
if err := tools.Chmod(website.Path, 0755); err != nil {
|
||||
return models.Website{}, err
|
||||
}
|
||||
tools.Chown(r.setting.Get(models.SettingKeyWebsitePath), "www", "www")
|
||||
tools.Chown(website.Path, "www", "www")
|
||||
|
||||
|
||||
@@ -106,16 +106,8 @@ func Mkdir(path string, permission os.FileMode) error {
|
||||
}
|
||||
|
||||
// Chmod 修改文件/目录权限
|
||||
func Chmod(path string, permission os.FileMode) bool {
|
||||
if err := os.Chmod(path, permission); err != nil {
|
||||
facades.Log().With(map[string]any{
|
||||
"path": path,
|
||||
"permission": permission,
|
||||
}).Tags("面板", "工具函数").Info("修改文件/目录权限失败")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
func Chmod(path string, permission os.FileMode) error {
|
||||
return os.Chmod(path, permission)
|
||||
}
|
||||
|
||||
// Chown 修改文件/目录所有者
|
||||
|
||||
@@ -78,7 +78,7 @@ func (s *SystemHelperTestSuite) TestChmod() {
|
||||
err := os.WriteFile(filePath, []byte("test data"), 0644)
|
||||
s.Nil(err)
|
||||
|
||||
s.True(Chmod(filePath, 0755))
|
||||
s.Nil(Chmod(filePath, 0755))
|
||||
}
|
||||
|
||||
func (s *SystemHelperTestSuite) TestChown() {
|
||||
|
||||
Reference in New Issue
Block a user