github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/vfs/default_windows.go (about)

     1  // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  //go:build windows
     6  // +build windows
     7  
     8  package vfs
     9  
    10  import (
    11  	"os"
    12  	"syscall"
    13  
    14  	"github.com/cockroachdb/errors"
    15  )
    16  
    17  func wrapOSFileImpl(f *os.File) File {
    18  	return &windowsFile{f}
    19  }
    20  
    21  func (defaultFS) OpenDir(name string) (File, error) {
    22  	f, err := os.OpenFile(name, syscall.O_CLOEXEC, 0)
    23  	if err != nil {
    24  		return nil, errors.WithStack(err)
    25  	}
    26  	return &windowsDir{f}, nil
    27  }
    28  
    29  // Assert that windowsFile and windowsDir implement vfs.File.
    30  var (
    31  	_ File = (*windowsFile)(nil)
    32  	_ File = (*windowsDir)(nil)
    33  )
    34  
    35  type windowsDir struct {
    36  	*os.File
    37  }
    38  
    39  func (*windowsDir) Prefetch(offset int64, length int64) error { return nil }
    40  func (*windowsDir) Preallocate(off, length int64) error       { return nil }
    41  
    42  // Silently ignore Sync() on Windows. This is the same behavior as
    43  // RocksDB. See port/win/io_win.cc:WinDirectory::Fsync().
    44  func (*windowsDir) Sync() error                                    { return nil }
    45  func (*windowsDir) SyncData() error                                { return nil }
    46  func (*windowsDir) SyncTo(length int64) (fullSync bool, err error) { return false, nil }
    47  
    48  type windowsFile struct {
    49  	*os.File
    50  }
    51  
    52  func (*windowsFile) Prefetch(offset int64, length int64) error { return nil }
    53  func (*windowsFile) Preallocate(offset, length int64) error    { return nil }
    54  
    55  func (f *windowsFile) SyncData() error { return f.Sync() }
    56  func (f *windowsFile) SyncTo(length int64) (fullSync bool, err error) {
    57  	if err = f.Sync(); err != nil {
    58  		return false, err
    59  	}
    60  	return true, nil
    61  }