Make atomic file replacement crash durable
This commit is contained in:
@@ -4,6 +4,7 @@ package fileops
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
@@ -29,12 +30,12 @@ func syncDirectory(path string) error {
|
||||
|
||||
err = windows.FlushFileBuffers(directory)
|
||||
// Windows filesystems may reject flushing a directory handle even when it
|
||||
// was opened correctly. Preserve every error except the documented forms
|
||||
// that mean this operation is unavailable for the handle or filesystem.
|
||||
// was opened correctly. Report documented unavailable forms explicitly so
|
||||
// callers do not confuse visible replacement with a durable one.
|
||||
if errors.Is(err, windows.ERROR_INVALID_FUNCTION) ||
|
||||
errors.Is(err, windows.ERROR_INVALID_HANDLE) ||
|
||||
errors.Is(err, windows.ERROR_NOT_SUPPORTED) {
|
||||
return nil
|
||||
return fmt.Errorf("%w for %q: %w", ErrDirectorySyncUnsupported, path, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user