fix: error check on state
This commit is contained in:
parent
b6927c9a7a
commit
df33d0215a
1 changed files with 9 additions and 3 deletions
|
|
@ -40,7 +40,9 @@ func NewManager(workspace string) *Manager {
|
||||||
oldStateFile := filepath.Join(workspace, "state.json")
|
oldStateFile := filepath.Join(workspace, "state.json")
|
||||||
|
|
||||||
// Create state directory if it doesn't exist
|
// Create state directory if it doesn't exist
|
||||||
os.MkdirAll(stateDir, 0o755)
|
if err := os.MkdirAll(stateDir, 0o755); err != nil {
|
||||||
|
log.Printf("[WARN] state: failed to create state directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
sm := &Manager{
|
sm := &Manager{
|
||||||
workspace: workspace,
|
workspace: workspace,
|
||||||
|
|
@ -54,13 +56,17 @@ func NewManager(workspace string) *Manager {
|
||||||
if data, err := os.ReadFile(oldStateFile); err == nil {
|
if data, err := os.ReadFile(oldStateFile); err == nil {
|
||||||
if err := json.Unmarshal(data, sm.state); err == nil {
|
if err := json.Unmarshal(data, sm.state); err == nil {
|
||||||
// Migrate to new location
|
// Migrate to new location
|
||||||
sm.saveAtomic()
|
if err := sm.saveAtomic(); err != nil {
|
||||||
|
log.Printf("[WARN] state: failed to save state: %v", err)
|
||||||
|
}
|
||||||
log.Printf("[INFO] state: migrated state from %s to %s", oldStateFile, stateFile)
|
log.Printf("[INFO] state: migrated state from %s to %s", oldStateFile, stateFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Load from new location
|
// Load from new location
|
||||||
sm.load()
|
if err := sm.load(); err != nil {
|
||||||
|
log.Printf("[WARN] state: failed to load state: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sm
|
return sm
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue