26 lines
508 B
Go
26 lines
508 B
Go
//go:build linux || darwin
|
|
|
|
package fileops
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
func syncDirectory(path string) error {
|
|
directory, err := os.Open(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
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.
|
|
if errors.Is(err, syscall.EINVAL) || errors.Is(err, syscall.ENOTSUP) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|