37d280da41
* core, eth: some fixes for freezer * vendor, core/rawdb, cmd/geth: add db inspector * core, cmd/utils: check ancient store path forceily * cmd/geth, common, core/rawdb: a few fixes * cmd/geth: support windows file rename and fix rename error * core: support ancient plugin * core, cmd: streaming file copy * cmd, consensus, core, tests: keep genesis in leveldb * core: write txlookup during ancient init * core: bump database version
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
|
|
// All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style license.
|
|
//
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
func rename(oldpath, newpath string) error {
|
|
return os.Rename(oldpath, newpath)
|
|
}
|
|
|
|
func isErrInvalid(err error) bool {
|
|
if err == os.ErrInvalid {
|
|
return true
|
|
}
|
|
// Go < 1.8
|
|
if syserr, ok := err.(*os.SyscallError); ok && syserr.Err == syscall.EINVAL {
|
|
return true
|
|
}
|
|
// Go >= 1.8 returns *os.PathError instead
|
|
if patherr, ok := err.(*os.PathError); ok && patherr.Err == syscall.EINVAL {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func syncDir(name string) error {
|
|
// As per fsync manpage, Linux seems to expect fsync on directory, however
|
|
// some system don't support this, so we will ignore syscall.EINVAL.
|
|
//
|
|
// From fsync(2):
|
|
// Calling fsync() does not necessarily ensure that the entry in the
|
|
// directory containing the file has also reached disk. For that an
|
|
// explicit fsync() on a file descriptor for the directory is also needed.
|
|
f, err := os.Open(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
if err := f.Sync(); err != nil && !isErrInvalid(err) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|