vendor: github.com/moby/sys/sequential v0.6.0

full diff: https://github.com/moby/sys/compare/sequential/v0.5.0...sequential/v0.6.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-07-25 14:56:13 +02:00
parent ea37ac9bac
commit b34e8e4dff
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
5 changed files with 53 additions and 71 deletions

View File

@ -25,7 +25,7 @@ require (
github.com/mattn/go-runewidth v0.0.15 github.com/mattn/go-runewidth v0.0.15
github.com/moby/patternmatcher v0.6.0 github.com/moby/patternmatcher v0.6.0
github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb
github.com/moby/sys/sequential v0.5.0 github.com/moby/sys/sequential v0.6.0
github.com/moby/sys/signal v0.7.1 github.com/moby/sys/signal v0.7.1
github.com/moby/term v0.5.0 github.com/moby/term v0.5.0
github.com/morikuni/aec v1.0.0 github.com/morikuni/aec v1.0.0

View File

@ -181,8 +181,8 @@ github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkV
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb h1:1UTTg2EgO3nuyV03wREDzldqqePzQ4+0a5G1C1y1bIo= github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb h1:1UTTg2EgO3nuyV03wREDzldqqePzQ4+0a5G1C1y1bIo=
github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb/go.mod h1:kNy225f/gWAnF8wPftteMc5nbAHhrH+HUfvyjmhFjeQ= github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb/go.mod h1:kNy225f/gWAnF8wPftteMc5nbAHhrH+HUfvyjmhFjeQ=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
github.com/moby/sys/signal v0.7.1 h1:PrQxdvxcGijdo6UXXo/lU/TvHUWyPhj7UOpSo8tuvk0= github.com/moby/sys/signal v0.7.1 h1:PrQxdvxcGijdo6UXXo/lU/TvHUWyPhj7UOpSo8tuvk0=
github.com/moby/sys/signal v0.7.1/go.mod h1:Se1VGehYokAkrSQwL4tDzHvETwUZlnY7S5XtQ50mQp8= github.com/moby/sys/signal v0.7.1/go.mod h1:Se1VGehYokAkrSQwL4tDzHvETwUZlnY7S5XtQ50mQp8=
github.com/moby/sys/symlink v0.3.0 h1:GZX89mEZ9u53f97npBy4Rc3vJKj7JBDj/PN2I22GrNU= github.com/moby/sys/symlink v0.3.0 h1:GZX89mEZ9u53f97npBy4Rc3vJKj7JBDj/PN2I22GrNU=

View File

@ -5,41 +5,22 @@ package sequential
import "os" import "os"
// Create creates the named file with mode 0666 (before umask), truncating // Create is an alias for [os.Create] on non-Windows platforms.
// it if it already exists. If successful, methods on the returned
// File can be used for I/O; the associated file descriptor has mode
// O_RDWR.
// If there is an error, it will be of type *PathError.
func Create(name string) (*os.File, error) { func Create(name string) (*os.File, error) {
return os.Create(name) return os.Create(name)
} }
// Open opens the named file for reading. If successful, methods on // Open is an alias for [os.Open] on non-Windows platforms.
// the returned file can be used for reading; the associated file
// descriptor has mode O_RDONLY.
// If there is an error, it will be of type *PathError.
func Open(name string) (*os.File, error) { func Open(name string) (*os.File, error) {
return os.Open(name) return os.Open(name)
} }
// OpenFile is the generalized open call; most users will use Open // OpenFile is an alias for [os.OpenFile] on non-Windows platforms.
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// If there is an error, it will be of type *PathError.
func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
return os.OpenFile(name, flag, perm) return os.OpenFile(name, flag, perm)
} }
// CreateTemp creates a new temporary file in the directory dir // CreateTemp is an alias for [os.CreateTemp] on non-Windows platforms.
// with a name beginning with prefix, opens the file for reading
// and writing, and returns the resulting *os.File.
// If dir is the empty string, TempFile uses the default directory
// for temporary files (see os.TempDir).
// Multiple programs calling TempFile simultaneously
// will not choose the same file. The caller can use f.Name()
// to find the pathname of the file. It is the caller's responsibility
// to remove the file when no longer needed.
func CreateTemp(dir, prefix string) (f *os.File, err error) { func CreateTemp(dir, prefix string) (f *os.File, err error) {
return os.CreateTemp(dir, prefix) return os.CreateTemp(dir, prefix)
} }

View File

@ -5,48 +5,52 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"sync" "sync"
"syscall"
"time" "time"
"unsafe" "unsafe"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
// Create creates the named file with mode 0666 (before umask), truncating // Create is a copy of [os.Create], modified to use sequential file access.
// it if it already exists. If successful, methods on the returned //
// File can be used for I/O; the associated file descriptor has mode // It uses [windows.FILE_FLAG_SEQUENTIAL_SCAN] rather than [windows.FILE_ATTRIBUTE_NORMAL]
// O_RDWR. // as implemented in golang. Refer to the [Win32 API documentation] for details
// If there is an error, it will be of type *PathError. // on sequential file access.
//
// [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
func Create(name string) (*os.File, error) { func Create(name string) (*os.File, error) {
return OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0) return openFileSequential(name, windows.O_RDWR|windows.O_CREAT|windows.O_TRUNC)
} }
// Open opens the named file for reading. If successful, methods on // Open is a copy of [os.Open], modified to use sequential file access.
// the returned file can be used for reading; the associated file //
// descriptor has mode O_RDONLY. // It uses [windows.FILE_FLAG_SEQUENTIAL_SCAN] rather than [windows.FILE_ATTRIBUTE_NORMAL]
// If there is an error, it will be of type *PathError. // as implemented in golang. Refer to the [Win32 API documentation] for details
// on sequential file access.
//
// [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
func Open(name string) (*os.File, error) { func Open(name string) (*os.File, error) {
return OpenFile(name, os.O_RDONLY, 0) return openFileSequential(name, windows.O_RDONLY)
} }
// OpenFile is the generalized open call; most users will use Open // OpenFile is a copy of [os.OpenFile], modified to use sequential file access.
// or Create instead. //
// If there is an error, it will be of type *PathError. // It uses [windows.FILE_FLAG_SEQUENTIAL_SCAN] rather than [windows.FILE_ATTRIBUTE_NORMAL]
// as implemented in golang. Refer to the [Win32 API documentation] for details
// on sequential file access.
//
// [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
func OpenFile(name string, flag int, _ os.FileMode) (*os.File, error) { func OpenFile(name string, flag int, _ os.FileMode) (*os.File, error) {
if name == "" { return openFileSequential(name, flag)
return nil, &os.PathError{Op: "open", Path: name, Err: syscall.ENOENT}
}
r, err := openFileSequential(name, flag, 0)
if err == nil {
return r, nil
}
return nil, &os.PathError{Op: "open", Path: name, Err: err}
} }
func openFileSequential(name string, flag int, _ os.FileMode) (file *os.File, err error) { func openFileSequential(name string, flag int) (file *os.File, err error) {
r, e := openSequential(name, flag|windows.O_CLOEXEC, 0) if name == "" {
return nil, &os.PathError{Op: "open", Path: name, Err: windows.ERROR_FILE_NOT_FOUND}
}
r, e := openSequential(name, flag|windows.O_CLOEXEC)
if e != nil { if e != nil {
return nil, e return nil, &os.PathError{Op: "open", Path: name, Err: e}
} }
return os.NewFile(uintptr(r), name), nil return os.NewFile(uintptr(r), name), nil
} }
@ -58,7 +62,7 @@ func makeInheritSa() *windows.SecurityAttributes {
return &sa return &sa
} }
func openSequential(path string, mode int, _ uint32) (fd windows.Handle, err error) { func openSequential(path string, mode int) (fd windows.Handle, err error) {
if len(path) == 0 { if len(path) == 0 {
return windows.InvalidHandle, windows.ERROR_FILE_NOT_FOUND return windows.InvalidHandle, windows.ERROR_FILE_NOT_FOUND
} }
@ -101,15 +105,16 @@ func openSequential(path string, mode int, _ uint32) (fd windows.Handle, err err
createmode = windows.OPEN_EXISTING createmode = windows.OPEN_EXISTING
} }
// Use FILE_FLAG_SEQUENTIAL_SCAN rather than FILE_ATTRIBUTE_NORMAL as implemented in golang. // Use FILE_FLAG_SEQUENTIAL_SCAN rather than FILE_ATTRIBUTE_NORMAL as implemented in golang.
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx // https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
const fileFlagSequentialScan = 0x08000000 // FILE_FLAG_SEQUENTIAL_SCAN h, e := windows.CreateFile(pathp, access, sharemode, sa, createmode, windows.FILE_FLAG_SEQUENTIAL_SCAN, 0)
h, e := windows.CreateFile(pathp, access, sharemode, sa, createmode, fileFlagSequentialScan, 0)
return h, e return h, e
} }
// Helpers for CreateTemp // Helpers for CreateTemp
var rand uint32 var (
var randmu sync.Mutex rand uint32
randmu sync.Mutex
)
func reseed() uint32 { func reseed() uint32 {
return uint32(time.Now().UnixNano() + int64(os.Getpid())) return uint32(time.Now().UnixNano() + int64(os.Getpid()))
@ -127,17 +132,13 @@ func nextSuffix() string {
return strconv.Itoa(int(1e9 + r%1e9))[1:] return strconv.Itoa(int(1e9 + r%1e9))[1:]
} }
// CreateTemp is a copy of os.CreateTemp, modified to use sequential // CreateTemp is a copy of [os.CreateTemp], modified to use sequential file access.
// file access. Below is the original comment from golang: //
// TempFile creates a new temporary file in the directory dir // It uses [windows.FILE_FLAG_SEQUENTIAL_SCAN] rather than [windows.FILE_ATTRIBUTE_NORMAL]
// with a name beginning with prefix, opens the file for reading // as implemented in golang. Refer to the [Win32 API documentation] for details
// and writing, and returns the resulting *os.File. // on sequential file access.
// If dir is the empty string, TempFile uses the default directory //
// for temporary files (see os.TempDir). // [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
// Multiple programs calling TempFile simultaneously
// will not choose the same file. The caller can use f.Name()
// to find the pathname of the file. It is the caller's responsibility
// to remove the file when no longer needed.
func CreateTemp(dir, prefix string) (f *os.File, err error) { func CreateTemp(dir, prefix string) (f *os.File, err error) {
if dir == "" { if dir == "" {
dir = os.TempDir() dir = os.TempDir()
@ -146,7 +147,7 @@ func CreateTemp(dir, prefix string) (f *os.File, err error) {
nconflict := 0 nconflict := 0
for i := 0; i < 10000; i++ { for i := 0; i < 10000; i++ {
name := filepath.Join(dir, prefix+nextSuffix()) name := filepath.Join(dir, prefix+nextSuffix())
f, err = OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600) f, err = openFileSequential(name, windows.O_RDWR|windows.O_CREAT|windows.O_EXCL)
if os.IsExist(err) { if os.IsExist(err) {
if nconflict++; nconflict > 10 { if nconflict++; nconflict > 10 {
randmu.Lock() randmu.Lock()

2
vendor/modules.txt vendored
View File

@ -205,7 +205,7 @@ github.com/moby/swarmkit/v2/api/defaults
github.com/moby/swarmkit/v2/api/genericresource github.com/moby/swarmkit/v2/api/genericresource
github.com/moby/swarmkit/v2/manager/raftselector github.com/moby/swarmkit/v2/manager/raftselector
github.com/moby/swarmkit/v2/protobuf/plugin github.com/moby/swarmkit/v2/protobuf/plugin
# github.com/moby/sys/sequential v0.5.0 # github.com/moby/sys/sequential v0.6.0
## explicit; go 1.17 ## explicit; go 1.17
github.com/moby/sys/sequential github.com/moby/sys/sequential
# github.com/moby/sys/signal v0.7.1 # github.com/moby/sys/signal v0.7.1