-
Notifications
You must be signed in to change notification settings - Fork 467
/
default_windows.go
65 lines (51 loc) · 1.74 KB
/
default_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2014 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//go:build windows
// +build windows
package vfs
import (
"os"
"syscall"
"github.com/cockroachdb/errors"
)
func wrapOSFile(f *os.File) File {
return &windowsFile{f}
}
func (defaultFS) OpenDir(name string) (File, error) {
f, err := os.OpenFile(name, syscall.O_CLOEXEC, 0)
if err != nil {
return nil, errors.WithStack(err)
}
return &windowsDir{f}, nil
}
// Assert that windowsFile and windowsDir implement vfs.File.
var (
_ File = (*windowsFile)(nil)
_ File = (*windowsDir)(nil)
)
type windowsDir struct {
*os.File
}
func (*windowsDir) Attributes() FileAttributes { return FileAttributes{} }
func (*windowsDir) Preallocate(off, length int64) error { return nil }
// Silently ignore Sync() on Windows. This is the same behavior as
// RocksDB. See port/win/io_win.cc:WinDirectory::Fsync().
func (*windowsDir) Sync() error { return nil }
func (*windowsDir) SyncData() error { return nil }
func (*windowsDir) SyncTo(length int64) error { return nil }
type windowsFile struct {
*os.File
}
func (*windowsFile) Attributes() FileAttributes {
// No support for sync_file_range.
return FileAttributes{CanSyncTo: false}
}
func (*windowsFile) Preallocate(offset, length int64) error {
// It is ok for correctness to no-op file preallocation. WAL recycling is the
// more important mechanism for WAL sync performance and it doesn't rely on
// fallocate or posix_fallocate in order to be effective.
return nil
}
func (f *windowsFile) SyncData() error { return f.Sync() }
func (f *windowsFile) SyncTo(length int64) error { return f.Sync() }