From 501f798b6fc98e24b7b96d2382f44c321757c054 Mon Sep 17 00:00:00 2001 From: vsmk98 Date: Tue, 23 Oct 2018 10:40:34 +0800 Subject: [PATCH] cherry pick ff2d4d2cedc09db23cc46d3eeb8b402bca6d819d for package rjeczalik --- vendor/github.com/rjeczalik/notify/node.go | 7 ++----- .../rjeczalik/notify/watcher_fsevents_cgo.go | 13 +++++-------- .../rjeczalik/notify/watcher_fsevents_go1.10.go | 9 +++++++++ .../rjeczalik/notify/watcher_fsevents_go1.9.go | 14 ++++++++++++++ vendor/vendor.json | 6 +++--- 5 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.10.go create mode 100644 vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.9.go diff --git a/vendor/github.com/rjeczalik/notify/node.go b/vendor/github.com/rjeczalik/notify/node.go index aced8b9c4..29c1bb20a 100644 --- a/vendor/github.com/rjeczalik/notify/node.go +++ b/vendor/github.com/rjeczalik/notify/node.go @@ -6,6 +6,7 @@ package notify import ( "errors" + "fmt" "io/ioutil" "os" "path/filepath" @@ -70,11 +71,7 @@ Traverse: case errSkip: continue Traverse default: - return &os.PathError{ - Op: "error while traversing", - Path: nd.Name, - Err: err, - } + return fmt.Errorf("error while traversing %q: %v", nd.Name, err) } // TODO(rjeczalik): tolerate open failures - add failed names to // AddDirError and notify users which names are not added to the tree. diff --git a/vendor/github.com/rjeczalik/notify/watcher_fsevents_cgo.go b/vendor/github.com/rjeczalik/notify/watcher_fsevents_cgo.go index a2b332a2e..fb70de6af 100644 --- a/vendor/github.com/rjeczalik/notify/watcher_fsevents_cgo.go +++ b/vendor/github.com/rjeczalik/notify/watcher_fsevents_cgo.go @@ -26,9 +26,9 @@ import "C" import ( "errors" "os" - "runtime" "sync" "sync/atomic" + "time" "unsafe" ) @@ -48,7 +48,7 @@ var wg sync.WaitGroup // used to wait until the runloop starts // started and is ready via the wg. It also serves purpose of a dummy source, // thanks to it the runloop does not return as it also has at least one source // registered. -var source = C.CFRunLoopSourceCreate(nil, 0, &C.CFRunLoopSourceContext{ +var source = C.CFRunLoopSourceCreate(refZero, 0, &C.CFRunLoopSourceContext{ perform: (C.CFRunLoopPerformCallBack)(C.gosource), }) @@ -63,10 +63,6 @@ var ( func init() { wg.Add(1) go func() { - // There is exactly one run loop per thread. Lock this goroutine to its - // thread to ensure that it's not rescheduled on a different thread while - // setting up the run loop. - runtime.LockOSThread() runloop = C.CFRunLoopGetCurrent() C.CFRunLoopAddSource(runloop, source, C.kCFRunLoopDefaultMode) C.CFRunLoopRun() @@ -77,6 +73,7 @@ func init() { //export gosource func gosource(unsafe.Pointer) { + time.Sleep(time.Second) wg.Done() } @@ -162,8 +159,8 @@ func (s *stream) Start() error { return nil } wg.Wait() - p := C.CFStringCreateWithCStringNoCopy(nil, C.CString(s.path), C.kCFStringEncodingUTF8, nil) - path := C.CFArrayCreate(nil, (*unsafe.Pointer)(unsafe.Pointer(&p)), 1, nil) + p := C.CFStringCreateWithCStringNoCopy(refZero, C.CString(s.path), C.kCFStringEncodingUTF8, refZero) + path := C.CFArrayCreate(refZero, (*unsafe.Pointer)(unsafe.Pointer(&p)), 1, nil) ctx := C.FSEventStreamContext{} ref := C.EventStreamCreate(&ctx, C.uintptr_t(s.info), path, C.FSEventStreamEventId(atomic.LoadUint64(&since)), latency, flags) if ref == nilstream { diff --git a/vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.10.go b/vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.10.go new file mode 100644 index 000000000..0edd3782f --- /dev/null +++ b/vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.10.go @@ -0,0 +1,9 @@ +// Copyright (c) 2017 The Notify Authors. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +// +build darwin,!kqueue,go1.10 + +package notify + +const refZero = 0 diff --git a/vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.9.go b/vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.9.go new file mode 100644 index 000000000..b81c3c185 --- /dev/null +++ b/vendor/github.com/rjeczalik/notify/watcher_fsevents_go1.9.go @@ -0,0 +1,14 @@ +// Copyright (c) 2017 The Notify Authors. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +// +build darwin,!kqueue,cgo,!go1.10 + +package notify + +/* +#include +*/ +import "C" + +var refZero = (*C.struct___CFAllocator)(nil) diff --git a/vendor/vendor.json b/vendor/vendor.json index 63d138dbd..021223608 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -346,10 +346,10 @@ "revisionTime": "2017-08-14T17:01:13Z" }, { - "checksumSHA1": "28UVHMmHx0iqO0XiJsjx+fwILyI=", + "checksumSHA1": "d2rQHpL6cSf3NQiWJCVoEiJhsOI=", "path": "github.com/rjeczalik/notify", - "revision": "c31e5f2cb22b3e4ef3f882f413847669bf2652b9", - "revisionTime": "2018-02-03T14:01:15Z" + "revision": "ff2d4d2cedc09db23cc46d3eeb8b402bca6d819d", + "revisionTime": "2017-12-09T07:29:52Z" }, { "checksumSHA1": "5uqO4ITTDMklKi3uNaE/D9LQ5nM=",