Harden backup paths and backup handling
This commit is contained in:
9
pages.go
9
pages.go
@@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/progress"
|
||||
@@ -72,7 +72,7 @@ func updateMainMenu(m model, msg tea.Msg) (model, tea.Cmd) {
|
||||
return m, m.codeInput.Focus()
|
||||
case 1:
|
||||
m.currentPage = pageVersionSelect
|
||||
m.logLines = nil // Bug2: 清除残留 logLines,否则版本列表被错误文本遮挡
|
||||
m.logLines = nil // Bug2: 清除残留 logLines,否则版本列表被错误文本遮挡
|
||||
m.versionList.SetItems(nil) // Bug10: 清除旧列表,避免短暂显示过时数据
|
||||
return m, scanVersions(m.exeDir)
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func updateExecuting(m model, msg tea.Msg) (model, tea.Cmd) {
|
||||
m.logLines = append(m.logLines, successStyle.Render("没有需要执行的操作"))
|
||||
return m, nil
|
||||
}
|
||||
m.backupDir = fmt.Sprintf("amt/backup/%s", time.Now().Format("20060102_150405"))
|
||||
m.backupDir = newBackupDir()
|
||||
m.logLines = append(m.logLines, boldStyle.Render(fmt.Sprintf("共 %d 个操作", len(m.actions))))
|
||||
m.logLines = append(m.logLines, describeAction(m.actions[0], 0, len(m.actions)))
|
||||
return m, tea.Batch(m.spinner.Tick, executeAction(m.versionDir, m.actions[0], 0, m.backupDir))
|
||||
@@ -200,6 +200,9 @@ func updateExecuting(m model, msg tea.Msg) (model, tea.Cmd) {
|
||||
m.progressCh = nil
|
||||
m.execErr = msg.err
|
||||
m.logLines = append(m.logLines, fmt.Sprintf("%s [%d/%d] 失败: %s", crossMark, msg.index+1, len(m.actions), msg.err.Error()))
|
||||
if m.backupDir != "" {
|
||||
m.logLines = append(m.logLines, subtleStyle.Render("备份目录: "+filepath.Join(m.versionDir, m.backupDir)))
|
||||
}
|
||||
return m, nil
|
||||
|
||||
case mirrorChoiceMsg:
|
||||
|
||||
Reference in New Issue
Block a user