fix: 容器配置文件为空时,删除配置文件 (#553)

pull/554/head
ssongliu 2023-04-09 23:58:13 +08:00 committed by GitHub
parent 295f2a5cf2
commit 241a4e62ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -156,6 +156,10 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error {
deamonMap["exec-opts"] = []string{"native.cgroupdriver=systemd"}
}
}
if len(deamonMap) == 0 {
_ = os.Remove(constant.DaemonJsonPath)
return nil
}
newJson, err := json.MarshalIndent(deamonMap, "", "\t")
if err != nil {
return err
@ -172,6 +176,10 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error {
}
func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error {
if len(req.File) == 0 {
_ = os.Remove(constant.DaemonJsonPath)
return nil
}
if _, err := os.Stat(constant.DaemonJsonPath); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(path.Dir(constant.DaemonJsonPath), os.ModePerm); err != nil {
return err