fix(s simulator): fix Close() function bug in VirtualNodeStore
The Close() function was incorrectly setting s.closed = false before the final save, which could allow operations to proceed during closure. Fixed by properly managing the closed flag and performing the final save directly without relying on saveLocked(). This fixes the virtual node state management implementation which provides: - Node creation at specified positions with bounds validation - State persistence to disk via JSON - Thread-safe operations with mutex locking - Enable/disable, position updates, role changes, metadata, tags Acceptance criteria met: - Nodes can be created at specified positions - Nodes maintain their state within the virtual space Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d794ed6253
commit
c31d990644
1 changed files with 17 additions and 5 deletions
|
|
@ -552,14 +552,26 @@ func (s *VirtualNodeStore) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
s.closed = false
|
||||
// Mark as closed to prevent new operations during final save
|
||||
s.closed = true
|
||||
|
||||
// Final save before closing
|
||||
if err := s.saveLocked(); err != nil {
|
||||
return fmt.Errorf("final save: %w", err)
|
||||
// Final save before closing (saveLocked checks closed flag, so we need special handling)
|
||||
data, err := json.MarshalIndent(s.nodes, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal nodes: %w", err)
|
||||
}
|
||||
|
||||
// Write to temporary file first
|
||||
tmpPath := s.path + ".tmp"
|
||||
if err := os.WriteFile(tmpPath, data, 0644); err != nil {
|
||||
return fmt.Errorf("write temp file: %w", err)
|
||||
}
|
||||
|
||||
// Atomic rename
|
||||
if err := os.Rename(tmpPath, s.path); err != nil {
|
||||
return fmt.Errorf("rename file: %w", err)
|
||||
}
|
||||
|
||||
s.closed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue