Make atomic file replacement crash durable

This commit is contained in:
2026-08-10 17:44:38 +00:00
parent 1dccf5f140
commit 59f3fe3d1d
13 changed files with 502 additions and 233 deletions

View File

@@ -4,6 +4,7 @@ package fileops
import (
"errors"
"fmt"
"os"
"syscall"
)
@@ -16,10 +17,10 @@ func syncDirectory(path string) error {
defer func() { _ = directory.Close() }()
err = directory.Sync()
// Some Unix filesystems do not implement directory syncing. Only their
// explicit unsupported-operation errors are safe to treat as best effort.
// Some Unix filesystems do not implement directory syncing. Report this
// explicitly so callers do not confuse visible replacement with a durable one.
if errors.Is(err, syscall.EINVAL) || errors.Is(err, syscall.ENOTSUP) {
return nil
return fmt.Errorf("%w for %q: %w", ErrDirectorySyncUnsupported, path, err)
}
return err
}