diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-14 02:41:48 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-14 02:41:48 -0500 |
commit | b2bae3c73817740b48a4698c6aa863d70234a64c (patch) | |
tree | 31cc4782cc8b79de5448b112f0641d0ac72e41d3 /inotify | |
parent | 3b2e46671e6d8356f9e236255bc0df805720cc3b (diff) |
Diffstat (limited to 'inotify')
-rw-r--r-- | inotify/go17.go | 27 | ||||
-rw-r--r-- | inotify/go18.go | 23 | ||||
-rw-r--r-- | inotify/inotify.go | 14 |
3 files changed, 56 insertions, 8 deletions
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 <lukeshu@sbcglobal.net>. +// +// 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 +// <http://www.gnu.org/licenses/>. + +// +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 <lukeshu@sbcglobal.net>. +// +// 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 +// <http://www.gnu.org/licenses/>. + +// +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 <lukeshu@sbcglobal.net>. +// Copyright 2015-2017 Luke Shumaker <lukeshu@sbcglobal.net>. // // 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 |