Upgrade versions of vendored libs

This commit is contained in:
eleksir
2022-11-04 16:29:14 +03:00
parent fba732cc24
commit a7ae372459
941 changed files with 219674 additions and 23611 deletions

View File

@@ -5,7 +5,7 @@
package vfs
import (
"io/ioutil"
"io"
"sort"
"github.com/cockroachdb/errors/oserror"
@@ -94,7 +94,7 @@ func Clone(srcFS, dstFS FS, srcPath, dstPath string, opts ...CloneOption) (bool,
return true, nil
}
data, err := ioutil.ReadAll(srcFile)
data, err := io.ReadAll(srcFile)
if err != nil {
return false, err
}

View File

@@ -35,7 +35,7 @@ func (defaultFS) GetDiskUsage(path string) (DiskUsage, error) {
// [2] https://man7.org/linux/man-pages/man3/statvfs.3.html
freeBytes := uint64(stat.Frsize) * uint64(stat.Bfree)
availBytes := uint64(stat.Frsize) * uint64(stat.Bavail)
totalBytes := uint64(stat.Bsize) * uint64(stat.Blocks)
totalBytes := uint64(stat.Frsize) * uint64(stat.Blocks)
return DiskUsage{
AvailBytes: availBytes,
TotalBytes: totalBytes,

View File

@@ -78,10 +78,23 @@ type MemFS struct {
strict bool
ignoreSyncs bool
// Windows has peculiar semantics with respect to hard links and deleting
// open files. In tests meant to exercise this behavior, this flag can be
// set to error if removing an open file.
windowsSemantics bool
}
var _ FS = &MemFS{}
// UseWindowsSemantics configures whether the MemFS implements Windows-style
// semantics, in particular with respect to whether any of an open file's links
// may be removed. Windows semantics default to off.
func (y *MemFS) UseWindowsSemantics(windowsSemantics bool) {
y.mu.Lock()
defer y.mu.Unlock()
y.windowsSemantics = windowsSemantics
}
// String dumps the contents of the MemFS.
func (y *MemFS) String() string {
y.mu.Lock()
@@ -303,11 +316,14 @@ func (y *MemFS) Remove(fullname string) error {
if !ok {
return oserror.ErrNotExist
}
// Disallow removal of open files/directories which implements Windows
// semantics. This ensures that we don't regress in the ordering of
// operations and try to remove a file while it is still open.
if n := atomic.LoadInt32(&child.refs); n > 0 {
return oserror.ErrInvalid
if y.windowsSemantics {
// Disallow removal of open files/directories which implements
// Windows semantics. This ensures that we don't regress in the
// ordering of operations and try to remove a file while it is
// still open.
if n := atomic.LoadInt32(&child.refs); n > 0 {
return oserror.ErrInvalid
}
}
if len(child.children) > 0 {
return errNotEmpty

View File

@@ -12,6 +12,7 @@ import (
// SyncingFileOptions holds the options for a syncingFile.
type SyncingFileOptions struct {
NoSyncOnClose bool
BytesPerSync int
PreallocateSize int
}
@@ -20,6 +21,8 @@ type syncingFile struct {
File
fd uintptr
useSyncRange bool
closing bool
noSyncOnClose bool
bytesPerSync int64
preallocateSize int64
atomic struct {
@@ -46,6 +49,7 @@ type syncingFile struct {
func NewSyncingFile(f File, opts SyncingFileOptions) File {
s := &syncingFile{
File: f,
noSyncOnClose: bool(opts.NoSyncOnClose),
bytesPerSync: int64(opts.BytesPerSync),
preallocateSize: int64(opts.PreallocateSize),
}
@@ -172,12 +176,16 @@ func (f *syncingFile) maybeSync() error {
}
func (f *syncingFile) Close() error {
// Sync any data that has been written but not yet synced. Note that if
// SyncFileRange was used, atomic.syncOffset will be less than
// Sync any data that has been written but not yet synced unless the file
// has noSyncOnClose option explicitly set.
// Note that if SyncFileRange was used, atomic.syncOffset will be less than
// atomic.offset. See syncingFile.syncToRange.
if atomic.LoadInt64(&f.atomic.offset) > atomic.LoadInt64(&f.atomic.syncOffset) {
if err := f.Sync(); err != nil {
return errors.WithStack(err)
f.closing = true
if !f.noSyncOnClose || f.useSyncRange {
if atomic.LoadInt64(&f.atomic.offset) > atomic.LoadInt64(&f.atomic.syncOffset) {
if err := f.Sync(); err != nil {
return errors.WithStack(err)
}
}
}
return errors.WithStack(f.File.Close())

View File

@@ -76,6 +76,14 @@ func (f *syncingFile) syncToRange(offset int64) error {
// waitAfter = 0x4
)
// The flags for the sync_file_range system call. Unless the file has
// noSyncOnClose explicitly set and it is being closed, the waitBefore
// flag will be set which may block the call.
flags := write
if !f.noSyncOnClose || !f.closing {
flags |= waitBefore
}
// Note that syncToRange is only called with an offset that is guaranteed to
// be less than atomic.offset (i.e. the write offset). This implies the
// syncingFile.Close will Sync the rest of the data, as well as the file's
@@ -91,7 +99,7 @@ func (f *syncingFile) syncToRange(offset int64) error {
// data accumulates, impacting other I/O operations.
var err error
f.timeDiskOp(func() {
err = syscall.SyncFileRange(int(f.fd), 0, offset, write|waitBefore)
err = syscall.SyncFileRange(int(f.fd), 0, offset, flags)
})
return err
}