mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-30 18:56:20 +08:00
fix: 解决 redis 配置修改失败的问题
This commit is contained in:
parent
fda2e832e9
commit
76a9c7f34b
1 changed files with 31 additions and 31 deletions
|
|
@ -221,41 +221,41 @@ func confSet(redisName string, changeConf []redisConfig) error {
|
||||||
}
|
}
|
||||||
files := strings.Split(string(lineBytes), "\n")
|
files := strings.Split(string(lineBytes), "\n")
|
||||||
|
|
||||||
isStartRange := false
|
startIndex, endIndex := 0, 0
|
||||||
isEndRange := false
|
|
||||||
var newFiles []string
|
var newFiles []string
|
||||||
for _, line := range files {
|
for i := 0; i < len(files); i++ {
|
||||||
if !isStartRange {
|
if files[i] == "# Redis configuration rewrite by 1Panel" {
|
||||||
if line == "# Redis configuration rewrite by 1Panel" {
|
startIndex = i
|
||||||
isStartRange = true
|
|
||||||
}
|
|
||||||
newFiles = append(newFiles, line)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if !isEndRange {
|
if files[i] == "# End Redis configuration rewrite by 1Panel" {
|
||||||
isExist := false
|
endIndex = i
|
||||||
for _, item := range changeConf {
|
break
|
||||||
if strings.HasPrefix(line, item.key) || strings.HasPrefix(line, "# "+item.key) {
|
|
||||||
if item.value == "0" || len(item.value) == 0 {
|
|
||||||
newFiles = append(newFiles, fmt.Sprintf("# %s %s", item.key, item.value))
|
|
||||||
} else {
|
|
||||||
newFiles = append(newFiles, fmt.Sprintf("%s %s", item.key, item.value))
|
|
||||||
}
|
|
||||||
isExist = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isExist {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
newFiles = append(newFiles, line)
|
|
||||||
if line == "# End Redis configuration rewrite by 1Panel" {
|
|
||||||
isEndRange = true
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
newFiles = append(newFiles, line)
|
newFiles = append(newFiles, files[i])
|
||||||
}
|
}
|
||||||
|
for _, item := range changeConf {
|
||||||
|
isExist := false
|
||||||
|
for i := startIndex; i < endIndex; i++ {
|
||||||
|
if strings.HasPrefix(newFiles[i], item.key) || strings.HasPrefix(newFiles[i], "# "+item.key) {
|
||||||
|
if item.value == "0" || len(item.value) == 0 {
|
||||||
|
newFiles[i] = fmt.Sprintf("# %s %s", item.key, item.value)
|
||||||
|
} else {
|
||||||
|
newFiles[i] = fmt.Sprintf("%s %s", item.key, item.value)
|
||||||
|
}
|
||||||
|
isExist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isExist {
|
||||||
|
if item.value == "0" || len(item.value) == 0 {
|
||||||
|
newFiles = append(newFiles, fmt.Sprintf("# %s %s", item.key, item.value))
|
||||||
|
} else {
|
||||||
|
newFiles = append(newFiles, fmt.Sprintf("%s %s", item.key, item.value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newFiles = append(newFiles, "# End Redis configuration rewrite by 1Panel")
|
||||||
|
|
||||||
file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0666)
|
file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue