fifo: Require that fifos do not exist for create
Although this operation is safe on linux, it is not safe on Windows when using the named pipe interface. To provide a ~reasonable common api abstraction, here we switch to returning File exists errors on the unix api.
This commit is contained in:
parent
0ff27cfc0f
commit
634ada671e
|
@ -11,18 +11,18 @@ import (
|
|||
)
|
||||
|
||||
// CreateAndRead creates a fifo at the given path, and returns an open function for reading.
|
||||
// The fifo must not exist already, or that it's already a fifo file
|
||||
// For compatibility with windows, the fifo must not exist already.
|
||||
//
|
||||
// It returns a reader open function that may block until a writer opens
|
||||
// so it's advised to run it in a goroutine different from reader goroutine
|
||||
func CreateAndRead(path string) (func() (io.ReadCloser, error), error) {
|
||||
// create first
|
||||
if err := mkfifo(path, 0600); err != nil && !os.IsExist(err) {
|
||||
if err := mkfifo(path, 0600); err != nil {
|
||||
return nil, fmt.Errorf("error creating fifo %v: %v", path, err)
|
||||
}
|
||||
|
||||
return func() (io.ReadCloser, error) {
|
||||
return os.OpenFile(path, unix.O_RDONLY, os.ModeNamedPipe)
|
||||
return OpenReader(path)
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue