Skip to content

Commit b8abb56

Browse files
committed
dir fix
1 parent 19bd795 commit b8abb56

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

core/rawdb/freezer_utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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

core/rawdb/freezer_utils_unix.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)