feat: implement atomic writes for filesystem backend
- Add WriteFile method to mock filesystem (non-atomic path, creates files) - Implement WriteFileAtomic in mock with temp file + rename pattern using .tmp/ directory, matching real filesystem semantics - Update WriteFileTask.Execute() to use WriteFileAtomic - Update FlushAll() to use WriteFileAtomic - Fix mock to create files on write (matching os.WriteFile behavior) - Update tests to match new semantics (create-if-not-exists)
This commit is contained in:
@@ -38,9 +38,16 @@ func (fs *RealFileSystem) ReadFile(path string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (fs *RealFileSystem) WriteFile(path string, content []byte) error {
|
||||
// Simple write for backward compatibility if needed,
|
||||
// but defer to Atomic implementation.
|
||||
return fs.WriteFileAtomic(path, content)
|
||||
}
|
||||
|
||||
func (fs *RealFileSystem) WriteFileAtomic(path string, content []byte) error {
|
||||
// Atomic write implementation
|
||||
fullPath := filepath.Join(fs.Root, path)
|
||||
tmpPath := filepath.Join(fs.Root, ".tmp", filepath.Base(path))
|
||||
// Temp file in the same directory as the target to ensure same filesystem rename
|
||||
tmpPath := filepath.Join(filepath.Dir(fullPath), "."+filepath.Base(path)+".tmp")
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(tmpPath), 0755); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user