go.mod: github.com/containerd/fifo v1.0.0

full diff: https://github.com/containerd/fifo/compare/115abcc95a1d...v1.0.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2021-03-25 16:13:44 +01:00
parent bbbd851381
commit 1c03c377e5
14 changed files with 23 additions and 74 deletions

1
vendor/github.com/containerd/fifo/.gitattributes generated vendored Normal file
View File

@@ -0,0 +1 @@
*.go text eol=lf

View File

@@ -16,9 +16,7 @@
package fifo
import (
"errors"
)
import "errors"
var (
ErrClosed = errors.New("fifo closed")

View File

@@ -1,3 +1,5 @@
// +build !windows
/*
Copyright The containerd Authors.
@@ -74,7 +76,7 @@ func OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.Re
func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo, error) {
if _, err := os.Stat(fn); err != nil {
if os.IsNotExist(err) && flag&syscall.O_CREAT != 0 {
if err := mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) {
if err := syscall.Mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating fifo %v", fn)
}
} else {

View File

@@ -1,4 +1,4 @@
// +build !linux
// +build !linux,!windows
/*
Copyright The containerd Authors.
@@ -38,8 +38,8 @@ func getHandle(fn string) (*handle, error) {
h := &handle{
fn: fn,
dev: uint64(stat.Dev),
ino: uint64(stat.Ino),
dev: uint64(stat.Dev), //nolint: unconvert
ino: uint64(stat.Ino), //nolint: unconvert
}
return h, nil
@@ -50,7 +50,7 @@ func (h *handle) Path() (string, error) {
if err := syscall.Stat(h.fn, &stat); err != nil {
return "", errors.Wrapf(err, "path %v could not be statted", h.fn)
}
if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino {
if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino { //nolint: unconvert
return "", errors.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
}
return h.fn, nil

View File

@@ -1,27 +0,0 @@
// +build solaris
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package fifo
import (
"golang.org/x/sys/unix"
)
func mkfifo(path string, mode uint32) (err error) {
return unix.Mkfifo(path, mode)
}

View File

@@ -1,4 +1,4 @@
// +build go1.12
// +build !windows
/*
Copyright The containerd Authors.

View File

@@ -1,5 +1,3 @@
// +build !solaris
/*
Copyright The containerd Authors.
@@ -18,8 +16,20 @@
package fifo
import "syscall"
import "os"
func mkfifo(path string, mode uint32) (err error) {
return syscall.Mkfifo(path, mode)
// IsFifo checks if a file is a (named pipe) fifo
// if the file does not exist then it returns false
func IsFifo(path string) (bool, error) {
stat, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
if stat.Mode()&os.ModeNamedPipe == os.ModeNamedPipe {
return true, nil
}
return false, nil
}