From b2bae3c73817740b48a4698c6aa863d70234a64c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 14 Jan 2017 02:41:48 -0500 Subject: On go 1.8, return os.ErrClosed on double-close. --- inotify/go17.go | 27 +++++++++++++++++++++++++++ inotify/go18.go | 23 +++++++++++++++++++++++ inotify/inotify.go | 14 ++++++-------- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 inotify/go17.go create mode 100644 inotify/go18.go diff --git a/inotify/go17.go b/inotify/go17.go new file mode 100644 index 0000000..a943d16 --- /dev/null +++ b/inotify/go17.go @@ -0,0 +1,27 @@ +// Copyright 2017 Luke Shumaker . +// +// This is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This software is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this manual; if not, see +// . + +// +build !go1.8 + +package inotify + +import ( + "os" + + "golang.org/x/sys/unix" +) + +var errClosed = os.NewSyscallError("close", unix.EBADF) diff --git a/inotify/go18.go b/inotify/go18.go new file mode 100644 index 0000000..0f083a0 --- /dev/null +++ b/inotify/go18.go @@ -0,0 +1,23 @@ +// Copyright 2017 Luke Shumaker . +// +// This is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This software is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this manual; if not, see +// . + +// +build go1.8 + +package inotify + +import "os" + +var errClosed = os.ErrClosed diff --git a/inotify/inotify.go b/inotify/inotify.go index d7e7044..7c80a00 100644 --- a/inotify/inotify.go +++ b/inotify/inotify.go @@ -1,4 +1,4 @@ -// Copyright 2015-2016 Luke Shumaker . +// Copyright 2015-2017 Luke Shumaker . // // This is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as @@ -157,16 +157,14 @@ func (in *Inotify) RmWatch(wd Wd) error { // Close closes the inotify instance; further calls to this object // will error. +// +// In the event of a double-close condition, in go <= 1.7, this +// returns an os.SyscallError wrapping unix.EBADF; on go >= 1.8, it +// returns os.ErrClosed. func (in *Inotify) Close() (err error) { defer func() { if r := recover(); r != nil { - // This is a double-close condition. - // - // Choices for the error: - // - Linux: EBADF - // - os.File: unix.EINVAL - // - net.netFD: net.errClosing = errors.New(...) - err = os.NewSyscallError("close", unix.EBADF) + err = errClosed } }() close(in.ch) // will panic if already closed; hence above -- cgit v1.2.3-2-g168b