Skip to content

Commit 7446a03

Browse files
committed
Merge branch 'v2' into v2-unstable.
2 parents 5466044 + 9856a29 commit 7446a03

32 files changed

+89
-71
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
22

3-
go_import_path: gopkg.in/mgo.v2-unstable
3+
go_import_path: gopkg.in/mgo.v2
44

55
addons:
66
apt:

auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"fmt"
3535
"sync"
3636

37-
"gopkg.in/mgo.v2-unstable/bson"
38-
"gopkg.in/mgo.v2-unstable/internal/scram"
37+
"gopkg.in/mgo.v2/bson"
38+
"gopkg.in/mgo.v2/internal/scram"
3939
)
4040

4141
type authCmd struct {

auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"time"
4040

4141
. "gopkg.in/check.v1"
42-
"gopkg.in/mgo.v2-unstable"
42+
"gopkg.in/mgo.v2"
4343
)
4444

4545
func (s *S) TestAuthLoginDatabase(c *C) {

bson/bson.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ package bson
3535
import (
3636
"bytes"
3737
"crypto/md5"
38-
"crypto/rand"
3938
"encoding/binary"
4039
"encoding/hex"
4140
"encoding/json"
4241
"errors"
4342
"fmt"
44-
"io"
4543
"os"
4644
"reflect"
4745
"runtime"
@@ -194,12 +192,10 @@ var objectIdCounter uint32 = readRandomUint32()
194192

195193
// readRandomUint32 returns a random objectIdCounter.
196194
func readRandomUint32() uint32 {
197-
var b [4]byte
198-
_, err := io.ReadFull(rand.Reader, b[:])
199-
if err != nil {
200-
panic(fmt.Errorf("cannot read random object id: %v", err))
201-
}
202-
return uint32((uint32(b[0]) << 0) | (uint32(b[1]) << 8) | (uint32(b[2]) << 16) | (uint32(b[3]) << 24))
195+
// We've found systems hanging in this function due to lack of entropy.
196+
// The randomness of these bytes is just preventing nearby clashes, so
197+
// just look at the time.
198+
return uint32(time.Now().UnixNano())
203199
}
204200

205201
// machineId stores machine id generated once and used in subsequent calls
@@ -214,10 +210,10 @@ func readMachineId() []byte {
214210
id := sum[:]
215211
hostname, err1 := os.Hostname()
216212
if err1 != nil {
217-
_, err2 := io.ReadFull(rand.Reader, id)
218-
if err2 != nil {
219-
panic(fmt.Errorf("cannot get hostname: %v; %v", err1, err2))
220-
}
213+
n := uint32(time.Now().UnixNano())
214+
sum[0] = byte(n >> 0)
215+
sum[1] = byte(n >> 8)
216+
sum[2] = byte(n >> 16)
221217
return id
222218
}
223219
hw := md5.New()
@@ -279,7 +275,7 @@ var nullBytes = []byte("null")
279275
func (id *ObjectId) UnmarshalJSON(data []byte) error {
280276
if len(data) > 0 && (data[0] == '{' || data[0] == 'O') {
281277
var v struct {
282-
Id json.RawMessage `json:"$oid"`
278+
Id json.RawMessage `json:"$oid"`
283279
Func struct {
284280
Id json.RawMessage
285281
} `json:"$oidFunc"`

bson/bson_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
"time"
4141

4242
. "gopkg.in/check.v1"
43-
"gopkg.in/mgo.v2-unstable/bson"
43+
"gopkg.in/mgo.v2/bson"
4444
"gopkg.in/yaml.v2"
4545
)
4646

bson/decimal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"regexp"
3434
"strings"
3535

36-
"gopkg.in/mgo.v2-unstable/bson"
36+
"gopkg.in/mgo.v2/bson"
3737

3838
. "gopkg.in/check.v1"
3939
)

bson/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/base64"
66
"fmt"
7-
"gopkg.in/mgo.v2-unstable/internal/json"
7+
"gopkg.in/mgo.v2/internal/json"
88
"strconv"
99
"time"
1010
)
@@ -317,7 +317,7 @@ func jencNumberLong(v interface{}) ([]byte, error) {
317317
func jencInt(v interface{}) ([]byte, error) {
318318
n := v.(int)
319319
f := `{"$numberLong":"%d"}`
320-
if n <= 1<<53 {
320+
if int64(n) <= 1<<53 {
321321
f = `%d`
322322
}
323323
return fbytes(f, n), nil

bson/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bson_test
22

33
import (
4-
"gopkg.in/mgo.v2-unstable/bson"
4+
"gopkg.in/mgo.v2/bson"
55

66
. "gopkg.in/check.v1"
77
"reflect"

bulk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"sort"
66

7-
"gopkg.in/mgo.v2-unstable/bson"
7+
"gopkg.in/mgo.v2/bson"
88
)
99

1010
// Bulk represents an operation that can be prepared with several

bulk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package mgo_test
2828

2929
import (
3030
. "gopkg.in/check.v1"
31-
"gopkg.in/mgo.v2-unstable"
31+
"gopkg.in/mgo.v2"
3232
)
3333

3434
func (s *S) TestBulkInsert(c *C) {

0 commit comments

Comments
 (0)