Make atomic file replacement crash durable
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user