File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ import (
2222 "path/filepath"
2323)
2424
25+ func atomicRename (src , dest string ) error {
26+ if err := os .Rename (src , dest ); err != nil {
27+ return err
28+ }
29+ return syncDir (filepath .Dir (src ))
30+ }
31+
2532// copyFrom copies data from 'srcPath' at offset 'offset' into 'destPath'.
2633// The 'destPath' is created if it doesn't exist, otherwise it is overwritten.
2734// Before the copy is executed, there is a callback can be registered to
Original file line number Diff line number Diff line change 1+ // Copyright 2022 The go-ethereum Authors
2+ // This file is part of the go-ethereum library.
3+ //
4+ // The go-ethereum library is free software: you can redistribute it and/or modify
5+ // it under the terms of the GNU Lesser General Public License as published by
6+ // the Free Software Foundation, either version 3 of the License, or
7+ // (at your option) any later version.
8+ //
9+ // The go-ethereum library is distributed in the hope that it will be useful,
10+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ // GNU Lesser General Public License for more details.
13+ //
14+ // You should have received a copy of the GNU Lesser General Public License
15+ // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+ //go:build !windows
18+ // +build !windows
19+
20+ package rawdb
21+
22+ import (
23+ "errors"
24+ "os"
25+ "syscall"
26+ )
27+
28+ // syncDir ensures that the directory metadata (e.g. newly renamed files)
29+ // is flushed to durable storage.
30+ func syncDir (name string ) error {
31+ f , err := os .Open (name )
32+ if err != nil {
33+ return err
34+ }
35+ defer f .Close ()
36+
37+ // Some file systems do not support fsyncing directories (e.g. some FUSE
38+ // mounts). Ignore EINVAL in those cases.
39+ if err := f .Sync (); err != nil {
40+ if errors .Is (err , os .ErrInvalid ) {
41+ return nil
42+ }
43+ if patherr , ok := err .(* os.PathError ); ok && patherr .Err == syscall .EINVAL {
44+ return nil
45+ }
46+ return err
47+ }
48+ return nil
49+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2022 The go-ethereum Authors
2+ // This file is part of the go-ethereum library.
3+ //
4+ // The go-ethereum library is free software: you can redistribute it and/or modify
5+ // it under the terms of the GNU Lesser General Public License as published by
6+ // the Free Software Foundation, either version 3 of the License, or
7+ // (at your option) any later version.
8+ //
9+ // The go-ethereum library is distributed in the hope that it will be useful,
10+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ // GNU Lesser General Public License for more details.
13+ //
14+ // You should have received a copy of the GNU Lesser General Public License
15+ // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+ //go:build windows
18+ // +build windows
19+
20+ package rawdb
21+
22+ // syncDir is a no-op on Windows. Fsyncing a directory handle is not
23+ // supported and returns "Access is denied".
24+ func syncDir (name string ) error {
25+ return nil
26+ }
You can’t perform that action at this time.
0 commit comments