From e6daf3b5bd581ccdeaa848b0ff7a1a55672a55fe Mon Sep 17 00:00:00 2001 From: Danielle Lancashire Date: Fri, 28 Jun 2019 13:35:41 +0200 Subject: [PATCH] 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. --- client/lib/fifo/fifo_unix.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/lib/fifo/fifo_unix.go b/client/lib/fifo/fifo_unix.go index 1533b0bee..c1d90a3ad 100644 --- a/client/lib/fifo/fifo_unix.go +++ b/client/lib/fifo/fifo_unix.go @@ -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 }