Browse code

Fix golang.org/x/sync canonical import path

The golang.org/x/sync package was vendored using the
github.com/golang/sync URL, but this is not the canonical
URL.

Because of this, vendoring failed in Moby, as it detects
these to be a duplicate import:

vndr github.com/golang/sync
2018/03/14 11:54:37 Collecting initial packages
2018/03/14 11:55:00 Download dependencies
2018/03/14 11:55:00 Failed to parse config: invalid config format: // FIXME this should be golang.org/x/sync, which is already vendored above

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2018/03/14 21:02:31
Showing 10 changed files
... ...
@@ -7,10 +7,9 @@ import (
7 7
 	"sync"
8 8
 	"testing"
9 9
 
10
-	"github.com/golang/sync/semaphore"
11
-
12 10
 	"github.com/docker/libnetwork/ipamapi"
13 11
 	"github.com/stretchr/testify/assert"
12
+	"golang.org/x/sync/semaphore"
14 13
 )
15 14
 
16 15
 const (
... ...
@@ -50,6 +50,6 @@ github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
50 50
 golang.org/x/crypto 558b6879de74bc843225cde5686419267ff707ca
51 51
 golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
52 52
 golang.org/x/sys 07c182904dbd53199946ba614a412c61d3c548f5
53
-github.com/golang/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5
53
+golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5
54 54
 github.com/pkg/errors 839d9e913e063e28dfd0e6c7b7512793e0a48be9
55 55
 github.com/ishidawataru/sctp 07191f837fedd2f13d1ec7b5f885f0f3ec54b1cb
56 56
deleted file mode 100644
... ...
@@ -1,27 +0,0 @@
1
-Copyright (c) 2009 The Go Authors. All rights reserved.
2
-
3
-Redistribution and use in source and binary forms, with or without
4
-modification, are permitted provided that the following conditions are
5
-met:
6
-
7
-   * Redistributions of source code must retain the above copyright
8
-notice, this list of conditions and the following disclaimer.
9
-   * Redistributions in binary form must reproduce the above
10
-copyright notice, this list of conditions and the following disclaimer
11
-in the documentation and/or other materials provided with the
12
-distribution.
13
-   * Neither the name of Google Inc. nor the names of its
14
-contributors may be used to endorse or promote products derived from
15
-this software without specific prior written permission.
16
-
17
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1
deleted file mode 100644
... ...
@@ -1,22 +0,0 @@
1
-Additional IP Rights Grant (Patents)
2
-
3
-"This implementation" means the copyrightable works distributed by
4
-Google as part of the Go project.
5
-
6
-Google hereby grants to You a perpetual, worldwide, non-exclusive,
7
-no-charge, royalty-free, irrevocable (except as stated in this section)
8
-patent license to make, have made, use, offer to sell, sell, import,
9
-transfer and otherwise run, modify and propagate the contents of this
10
-implementation of Go, where such license applies only to those patent
11
-claims, both currently owned or controlled by Google and acquired in
12
-the future, licensable by Google that are necessarily infringed by this
13
-implementation of Go.  This grant does not include claims that would be
14
-infringed only as a consequence of further modification of this
15
-implementation.  If you or your agent or exclusive licensee institute or
16
-order or agree to the institution of patent litigation against any
17
-entity (including a cross-claim or counterclaim in a lawsuit) alleging
18
-that this implementation of Go or any code incorporated within this
19
-implementation of Go constitutes direct or contributory patent
20
-infringement, or inducement of patent infringement, then any patent
21
-rights granted to you under this License for this implementation of Go
22
-shall terminate as of the date such litigation is filed.
23 1
deleted file mode 100644
... ...
@@ -1,18 +0,0 @@
1
-# Go Sync
2
-
3
-This repository provides Go concurrency primitives in addition to the
4
-ones provided by the language and "sync" and "sync/atomic" packages.
5
-
6
-## Download/Install
7
-
8
-The easiest way to install is to run `go get -u golang.org/x/sync`. You can
9
-also manually git clone the repository to `$GOPATH/src/golang.org/x/sync`.
10
-
11
-## Report Issues / Send Patches
12
-
13
-This repository uses Gerrit for code changes. To learn how to submit changes to
14
-this repository, see https://golang.org/doc/contribute.html.
15
-
16
-The main issue tracker for the sync repository is located at
17
-https://github.com/golang/go/issues. Prefix your issue with "x/sync:" in the
18
-subject line, so it is easy to find.
19 1
deleted file mode 100644
... ...
@@ -1,131 +0,0 @@
1
-// Copyright 2017 The Go Authors. All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-// Package semaphore provides a weighted semaphore implementation.
6
-package semaphore // import "golang.org/x/sync/semaphore"
7
-
8
-import (
9
-	"container/list"
10
-	"sync"
11
-
12
-	// Use the old context because packages that depend on this one
13
-	// (e.g. cloud.google.com/go/...) must run on Go 1.6.
14
-	// TODO(jba): update to "context" when possible.
15
-	"golang.org/x/net/context"
16
-)
17
-
18
-type waiter struct {
19
-	n     int64
20
-	ready chan<- struct{} // Closed when semaphore acquired.
21
-}
22
-
23
-// NewWeighted creates a new weighted semaphore with the given
24
-// maximum combined weight for concurrent access.
25
-func NewWeighted(n int64) *Weighted {
26
-	w := &Weighted{size: n}
27
-	return w
28
-}
29
-
30
-// Weighted provides a way to bound concurrent access to a resource.
31
-// The callers can request access with a given weight.
32
-type Weighted struct {
33
-	size    int64
34
-	cur     int64
35
-	mu      sync.Mutex
36
-	waiters list.List
37
-}
38
-
39
-// Acquire acquires the semaphore with a weight of n, blocking only until ctx
40
-// is done. On success, returns nil. On failure, returns ctx.Err() and leaves
41
-// the semaphore unchanged.
42
-//
43
-// If ctx is already done, Acquire may still succeed without blocking.
44
-func (s *Weighted) Acquire(ctx context.Context, n int64) error {
45
-	s.mu.Lock()
46
-	if s.size-s.cur >= n && s.waiters.Len() == 0 {
47
-		s.cur += n
48
-		s.mu.Unlock()
49
-		return nil
50
-	}
51
-
52
-	if n > s.size {
53
-		// Don't make other Acquire calls block on one that's doomed to fail.
54
-		s.mu.Unlock()
55
-		<-ctx.Done()
56
-		return ctx.Err()
57
-	}
58
-
59
-	ready := make(chan struct{})
60
-	w := waiter{n: n, ready: ready}
61
-	elem := s.waiters.PushBack(w)
62
-	s.mu.Unlock()
63
-
64
-	select {
65
-	case <-ctx.Done():
66
-		err := ctx.Err()
67
-		s.mu.Lock()
68
-		select {
69
-		case <-ready:
70
-			// Acquired the semaphore after we were canceled.  Rather than trying to
71
-			// fix up the queue, just pretend we didn't notice the cancelation.
72
-			err = nil
73
-		default:
74
-			s.waiters.Remove(elem)
75
-		}
76
-		s.mu.Unlock()
77
-		return err
78
-
79
-	case <-ready:
80
-		return nil
81
-	}
82
-}
83
-
84
-// TryAcquire acquires the semaphore with a weight of n without blocking.
85
-// On success, returns true. On failure, returns false and leaves the semaphore unchanged.
86
-func (s *Weighted) TryAcquire(n int64) bool {
87
-	s.mu.Lock()
88
-	success := s.size-s.cur >= n && s.waiters.Len() == 0
89
-	if success {
90
-		s.cur += n
91
-	}
92
-	s.mu.Unlock()
93
-	return success
94
-}
95
-
96
-// Release releases the semaphore with a weight of n.
97
-func (s *Weighted) Release(n int64) {
98
-	s.mu.Lock()
99
-	s.cur -= n
100
-	if s.cur < 0 {
101
-		s.mu.Unlock()
102
-		panic("semaphore: bad release")
103
-	}
104
-	for {
105
-		next := s.waiters.Front()
106
-		if next == nil {
107
-			break // No more waiters blocked.
108
-		}
109
-
110
-		w := next.Value.(waiter)
111
-		if s.size-s.cur < w.n {
112
-			// Not enough tokens for the next waiter.  We could keep going (to try to
113
-			// find a waiter with a smaller request), but under load that could cause
114
-			// starvation for large requests; instead, we leave all remaining waiters
115
-			// blocked.
116
-			//
117
-			// Consider a semaphore used as a read-write lock, with N tokens, N
118
-			// readers, and one writer.  Each reader can Acquire(1) to obtain a read
119
-			// lock.  The writer can Acquire(N) to obtain a write lock, excluding all
120
-			// of the readers.  If we allow the readers to jump ahead in the queue,
121
-			// the writer will starve — there is always one token available for every
122
-			// reader.
123
-			break
124
-		}
125
-
126
-		s.cur += w.n
127
-		s.waiters.Remove(next)
128
-		close(w.ready)
129
-	}
130
-	s.mu.Unlock()
131
-}
132 1
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+Copyright (c) 2009 The Go Authors. All rights reserved.
1
+
2
+Redistribution and use in source and binary forms, with or without
3
+modification, are permitted provided that the following conditions are
4
+met:
5
+
6
+   * Redistributions of source code must retain the above copyright
7
+notice, this list of conditions and the following disclaimer.
8
+   * Redistributions in binary form must reproduce the above
9
+copyright notice, this list of conditions and the following disclaimer
10
+in the documentation and/or other materials provided with the
11
+distribution.
12
+   * Neither the name of Google Inc. nor the names of its
13
+contributors may be used to endorse or promote products derived from
14
+this software without specific prior written permission.
15
+
16
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0 27
new file mode 100644
... ...
@@ -0,0 +1,22 @@
0
+Additional IP Rights Grant (Patents)
1
+
2
+"This implementation" means the copyrightable works distributed by
3
+Google as part of the Go project.
4
+
5
+Google hereby grants to You a perpetual, worldwide, non-exclusive,
6
+no-charge, royalty-free, irrevocable (except as stated in this section)
7
+patent license to make, have made, use, offer to sell, sell, import,
8
+transfer and otherwise run, modify and propagate the contents of this
9
+implementation of Go, where such license applies only to those patent
10
+claims, both currently owned or controlled by Google and acquired in
11
+the future, licensable by Google that are necessarily infringed by this
12
+implementation of Go.  This grant does not include claims that would be
13
+infringed only as a consequence of further modification of this
14
+implementation.  If you or your agent or exclusive licensee institute or
15
+order or agree to the institution of patent litigation against any
16
+entity (including a cross-claim or counterclaim in a lawsuit) alleging
17
+that this implementation of Go or any code incorporated within this
18
+implementation of Go constitutes direct or contributory patent
19
+infringement, or inducement of patent infringement, then any patent
20
+rights granted to you under this License for this implementation of Go
21
+shall terminate as of the date such litigation is filed.
0 22
new file mode 100644
... ...
@@ -0,0 +1,18 @@
0
+# Go Sync
1
+
2
+This repository provides Go concurrency primitives in addition to the
3
+ones provided by the language and "sync" and "sync/atomic" packages.
4
+
5
+## Download/Install
6
+
7
+The easiest way to install is to run `go get -u golang.org/x/sync`. You can
8
+also manually git clone the repository to `$GOPATH/src/golang.org/x/sync`.
9
+
10
+## Report Issues / Send Patches
11
+
12
+This repository uses Gerrit for code changes. To learn how to submit changes to
13
+this repository, see https://golang.org/doc/contribute.html.
14
+
15
+The main issue tracker for the sync repository is located at
16
+https://github.com/golang/go/issues. Prefix your issue with "x/sync:" in the
17
+subject line, so it is easy to find.
0 18
new file mode 100644
... ...
@@ -0,0 +1,131 @@
0
+// Copyright 2017 The Go Authors. All rights reserved.
1
+// Use of this source code is governed by a BSD-style
2
+// license that can be found in the LICENSE file.
3
+
4
+// Package semaphore provides a weighted semaphore implementation.
5
+package semaphore // import "golang.org/x/sync/semaphore"
6
+
7
+import (
8
+	"container/list"
9
+	"sync"
10
+
11
+	// Use the old context because packages that depend on this one
12
+	// (e.g. cloud.google.com/go/...) must run on Go 1.6.
13
+	// TODO(jba): update to "context" when possible.
14
+	"golang.org/x/net/context"
15
+)
16
+
17
+type waiter struct {
18
+	n     int64
19
+	ready chan<- struct{} // Closed when semaphore acquired.
20
+}
21
+
22
+// NewWeighted creates a new weighted semaphore with the given
23
+// maximum combined weight for concurrent access.
24
+func NewWeighted(n int64) *Weighted {
25
+	w := &Weighted{size: n}
26
+	return w
27
+}
28
+
29
+// Weighted provides a way to bound concurrent access to a resource.
30
+// The callers can request access with a given weight.
31
+type Weighted struct {
32
+	size    int64
33
+	cur     int64
34
+	mu      sync.Mutex
35
+	waiters list.List
36
+}
37
+
38
+// Acquire acquires the semaphore with a weight of n, blocking only until ctx
39
+// is done. On success, returns nil. On failure, returns ctx.Err() and leaves
40
+// the semaphore unchanged.
41
+//
42
+// If ctx is already done, Acquire may still succeed without blocking.
43
+func (s *Weighted) Acquire(ctx context.Context, n int64) error {
44
+	s.mu.Lock()
45
+	if s.size-s.cur >= n && s.waiters.Len() == 0 {
46
+		s.cur += n
47
+		s.mu.Unlock()
48
+		return nil
49
+	}
50
+
51
+	if n > s.size {
52
+		// Don't make other Acquire calls block on one that's doomed to fail.
53
+		s.mu.Unlock()
54
+		<-ctx.Done()
55
+		return ctx.Err()
56
+	}
57
+
58
+	ready := make(chan struct{})
59
+	w := waiter{n: n, ready: ready}
60
+	elem := s.waiters.PushBack(w)
61
+	s.mu.Unlock()
62
+
63
+	select {
64
+	case <-ctx.Done():
65
+		err := ctx.Err()
66
+		s.mu.Lock()
67
+		select {
68
+		case <-ready:
69
+			// Acquired the semaphore after we were canceled.  Rather than trying to
70
+			// fix up the queue, just pretend we didn't notice the cancelation.
71
+			err = nil
72
+		default:
73
+			s.waiters.Remove(elem)
74
+		}
75
+		s.mu.Unlock()
76
+		return err
77
+
78
+	case <-ready:
79
+		return nil
80
+	}
81
+}
82
+
83
+// TryAcquire acquires the semaphore with a weight of n without blocking.
84
+// On success, returns true. On failure, returns false and leaves the semaphore unchanged.
85
+func (s *Weighted) TryAcquire(n int64) bool {
86
+	s.mu.Lock()
87
+	success := s.size-s.cur >= n && s.waiters.Len() == 0
88
+	if success {
89
+		s.cur += n
90
+	}
91
+	s.mu.Unlock()
92
+	return success
93
+}
94
+
95
+// Release releases the semaphore with a weight of n.
96
+func (s *Weighted) Release(n int64) {
97
+	s.mu.Lock()
98
+	s.cur -= n
99
+	if s.cur < 0 {
100
+		s.mu.Unlock()
101
+		panic("semaphore: bad release")
102
+	}
103
+	for {
104
+		next := s.waiters.Front()
105
+		if next == nil {
106
+			break // No more waiters blocked.
107
+		}
108
+
109
+		w := next.Value.(waiter)
110
+		if s.size-s.cur < w.n {
111
+			// Not enough tokens for the next waiter.  We could keep going (to try to
112
+			// find a waiter with a smaller request), but under load that could cause
113
+			// starvation for large requests; instead, we leave all remaining waiters
114
+			// blocked.
115
+			//
116
+			// Consider a semaphore used as a read-write lock, with N tokens, N
117
+			// readers, and one writer.  Each reader can Acquire(1) to obtain a read
118
+			// lock.  The writer can Acquire(N) to obtain a write lock, excluding all
119
+			// of the readers.  If we allow the readers to jump ahead in the queue,
120
+			// the writer will starve — there is always one token available for every
121
+			// reader.
122
+			break
123
+		}
124
+
125
+		s.cur += w.n
126
+		s.waiters.Remove(next)
127
+		close(w.ready)
128
+	}
129
+	s.mu.Unlock()
130
+}