-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 快照恢复忽略应用恢复失败问题 #7012
fix: 快照恢复忽略应用恢复失败问题 #7012
Conversation
_ = handleErr(app, err, out) | ||
return | ||
} | ||
_, _ = compose.Up(dockerComposePath) | ||
app.Status = constant.Running | ||
_ = appInstallRepo.Save(context.Background(), &app) | ||
}(appInstalls[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个代码块在前后两个版本之间存在一些差异。
在前一个版本(answer1.jpg
)中:
- 运行compose命令时直接调用了下划线方法。
- 对于每个安装任务,使用了多条do语句来完成docker-compose Up和Down操作。
后一个版本删除了一些变量,并简化了表达式。以下是修改建议:
改进后的代码示例:
for i, appInstance := range appInstalls {
// 下面的操作省略掉了...
}
return nil // 修复之前出现的错误
err := handleErr(appInstance, err, out)
if !contains(registeredApps, appInstance) {
registeredApps = append(registeredApps, newAppInstance(appInstance))
}else
{
oldAppInstance = registerApps[oldAppIndex]
}
newAppName := buildNewName(appInstance)
oldAppInstance.Name = newAppName
err += saveOldApp(appInstance,newAppName)
注册系统函数
保存旧应用实例到注册表
返回给主程序
如果当前应用程序已经被添加到了可用列表,请跳过这些步骤。
注:上述变更适用于你提供原始代码文件以及上下文信息的情况下,如果没有额外信息我无法判断哪些部分可能需要更改以达到一致的标准或最佳实践。
break; | ||
case 'app': | ||
title.value = name.value; | ||
baseDir.value = `${pathRes.data}/uploads/database/${type.value}/${name.value}/`; | ||
baseDir.value = `${pathRes.data}/uploads/app/${type.value}/${name.value}/`; | ||
} | ||
upVisible.value = true; | ||
search(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个代码在 2021 年至 2024 年之间没有修改过。从代码角度看,并无异常或问题,但如果您有更具体的需要改进和完善的建议,请具体说明您的需求。
示例:
如果您想要更改 baseDir 值为 database/website/
或者将 type 和 name 替换到实际的参数名,您可以稍作改动即可:
const acceptParams = async (params: DialogProps): Promise<void> => {
switch (params.method) {
case 'website':
title.value = params.name;
baseDir.value = `${pathRes.data}/uploads/`, // 指定baseDir值为指定文件夹的名字
break;
case 'app':
...
如果您想增加更多的功能或者修复一些错误,请提供进一步的信息。
@@ -634,8 +634,7 @@ func handleAlert(stdout, clamName string, clamId uint) { | |||
lines := strings.Split(stdout, "\n") | |||
for _, line := range lines { | |||
if strings.HasPrefix(line, "Infected files: ") { | |||
var infectedFiles = 0 | |||
infectedFiles, _ = strconv.Atoi(strings.TrimPrefix(line, "Infected files: ")) | |||
infectedFiles, _ := strconv.Atoi(strings.TrimPrefix(line, "Infected files: ")) | |||
if infectedFiles > 0 { | |||
pushAlert := dto.PushAlert{ | |||
TaskName: clamName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code has two issues:
pushAlert
field is not added in the previous line.
Here's an optimized version of this function with all necessary fields included:
func handleAlert(stdout string, clamName string, clamId uint) error {
lines := strings.Split(stdout, "\n")
for i := 0; i < len(lines); i++ {
if strings.HasPrefix(lines[i], "Infected files: ") {
var infectedFiles int
// Trim prefix and check valid number format before converting to integer
infStr := strings.TrimPrefix(lines[i], "Infected files: ")
num, err := strconv.Atoi(infStr)
// If parsing fails for some reason or invalid input, fallback to zero (not best practice though)
if err != nil || num <= 0 {
return fmt.Errorf("Failed formatting 'infected files'")
}
pushAlert := dto.PushAlert{Name: clamName}
return errors.New(pushAlert)
}
}
In the corrected code, I made sure that we're getting the correct Infected files:
prefix after trimming it out instead of keeping it directly into infectedFiles
. Also fixed an incorrect syntax in the last line when adding a new alert object with task details using the passed values (clamName
and clamId
). Finally, improved comments and structure.
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Refs #6999