Skip to content

Commit 97ca7e9

Browse files
committed
2 parents f90bcfe + f4f4c7b commit 97ca7e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1728
-311
lines changed

.errcheck-excludes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
(github.com/mongodb/mongo-go-driver/core/connection.Connection).Close
33
(*github.com/mongodb/mongo-go-driver/core/topology.Subscription).Unsubscribe
44
(*github.com/mongodb/mongo-go-driver/core/topology.Server).Close
5+
(*github.com/mongodb/mongo-go-driver/core/connection.pool).closeConnection
6+
(net.Conn).Close
7+
encoding/pem.Encode

.evergreen/config.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ stepback: true
1010
# Mark a failure as a system/bootstrap failure (purple box) rather then a task
1111
# failure by default.
1212
# Actual testing tasks are marked with `type: test`
13-
command_type: system
13+
command_type: setup
1414

1515
# Protect ourself against rogue test case, or curl gone wild, that runs forever
1616
# 12 minutes is the longest we'll ever run
@@ -27,10 +27,9 @@ functions:
2727
fetch-source:
2828
# Executes git clone and applies the submitted patch, if any
2929
- command: git.get_project
30+
type: system
3031
params:
3132
directory: src/github.com/mongodb/mongo-go-driver
32-
# Deprecated. Should be removed. But still needed for certain agents (ZAP)
33-
- command: git.apply_patch
3433
# Make an evergreen expansion file with dynamic values
3534
- command: shell.exec
3635
params:
@@ -61,18 +60,14 @@ functions:
6160
export MONGO_ORCHESTRATION_HOME="$DRIVERS_TOOLS/.evergreen/orchestration"
6261
export MONGODB_BINARIES="$DRIVERS_TOOLS/mongodb/bin"
6362
export UPLOAD_BUCKET="${project}"
64-
export PATH="${GCC_PATH}:$GOPATH/bin:$MONGODB_BINARIES:$PATH"
63+
export PATH="${GO_DIST}/bin:${GCC_PATH}:$GOPATH/bin:$MONGODB_BINARIES:$PATH"
6564
export PROJECT="${project}"
6665
6766
if [ "Windows_NT" = "$OS" ]; then
6867
export USERPROFILE=$(cygpath -w $(dirname $(dirname $(dirname $(dirname `pwd`)))))
6968
export HOME=$(cygpath -w $(dirname $(dirname $(dirname $(dirname `pwd`)))))
7069
fi
7170
72-
go get -u github.com/andrewkroh/gvm
73-
eval "$(gvm -f bash 1.9.5)"
74-
gvm -f bash 1.9.5
75-
7671
go version
7772
go env
7873
@@ -87,7 +82,7 @@ functions:
8782
set -o errexit
8883
set -o xtrace
8984
export GOPATH="$GOPATH"
90-
export GOROOT="$GOROOT"
85+
export GOROOT="${GO_DIST}"
9186
export DRIVERS_TOOLS="$DRIVERS_TOOLS"
9287
export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME"
9388
export MONGODB_BINARIES="$MONGODB_BINARIES"
@@ -543,26 +538,29 @@ axes:
543538
- id: "windows-64"
544539
display_name: "Windows 64-bit"
545540
run_on:
546-
- windows-64-vs2015-compile
547541
- windows-64-vs2015-test
548-
- windows-64-vs2015-large
549542
variables:
550543
GCC_PATH: "/cygdrive/c/mingw-w64/x86_64-4.9.1-posix-seh-rt_v3-rev1/mingw64/bin"
551-
- id: "ubuntu1404-64"
552-
display_name: "Ubuntu 14.04"
553-
run_on: ubuntu1404-build
544+
GO_DIST: "C:\\golang\\go1.9.5"
545+
- id: "ubuntu1604-64"
546+
display_name: "Ubuntu 16.04"
547+
run_on: ubuntu1604-build
548+
variables:
549+
GO_DIST: "/opt/golang/go1.9"
554550
- id: osx
555551
display_name: "MacOS 10.12"
556552
run_on: macos-1012
553+
variables:
554+
GO_DIST: "/opt/golang/go1.9"
557555

558556

559557
buildvariants:
560558
- name: static-analysis
561559
display_name: "Static Analysis"
562560
run_on:
563-
# we don't care where this one runs
564-
- macos-1012
565-
- ubuntu1404-build
561+
- ubuntu1604-build
562+
expansions:
563+
GO_DIST: "/opt/golang/go1.9"
566564
tasks:
567565
- name: ".static-analysis"
568566

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lint-add-whitelist:
3939

4040
.PHONY: errcheck
4141
errcheck:
42-
errcheck -exclude .errcheck-excludes ./bson/... ./mongo/...
42+
errcheck -exclude .errcheck-excludes ./bson/... ./mongo/... ./core/...
4343

4444
.PHONY: test
4545
test:

bson/decode.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,9 @@ func (d *Decoder) decodeBSONArrayToSlice(sliceType reflect.Type) (reflect.Value,
702702
break
703703
}
704704

705+
if sliceType.Elem().Kind() == reflect.Ptr {
706+
elem = elem.Addr()
707+
}
705708
out.Index(i).Set(elem)
706709
}
707710

@@ -787,11 +790,12 @@ func matchesField(key string, field string, sType reflect.Type) bool {
787790

788791
tag, ok := sField.Tag.Lookup("bson")
789792
if !ok {
793+
// Get the full tag string
794+
tag = string(sField.Tag)
795+
790796
if len(sField.Tag) == 0 || strings.ContainsRune(tag, ':') {
791797
return strings.ToLower(key) == strings.ToLower(field)
792798
}
793-
794-
tag = string(sField.Tag)
795799
}
796800

797801
var fieldKey string

core/command/aggregate.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ func (a *Aggregate) Encode(desc description.SelectedServer) (wiremessage.WireMes
4949
if t == 0 && a.HasDollarOut() {
5050
continue
5151
}
52-
option.Option(cursor)
52+
err := option.Option(cursor)
53+
if err != nil {
54+
return nil, err
55+
}
5356
default:
54-
option.Option(command)
57+
err := option.Option(command)
58+
if err != nil {
59+
return nil, err
60+
}
5561
}
5662
}
5763

core/command/count.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ func (c *Count) Encode(desc description.SelectedServer) (wiremessage.WireMessage
4141
if option == nil {
4242
continue
4343
}
44-
option.Option(command)
44+
err := option.Option(command)
45+
if err != nil {
46+
return nil, err
47+
}
4548
}
4649

4750
return (&Command{DB: c.NS.DB, ReadPref: c.ReadPref, Command: command}).Encode(desc)

core/command/delete.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ func (d *Delete) Encode(desc description.SelectedServer) (wiremessage.WireMessag
4848
case nil:
4949
case options.OptCollation:
5050
for _, doc := range d.Deletes {
51-
option.Option(doc)
51+
err := option.Option(doc)
52+
if err != nil {
53+
return nil, err
54+
}
5255
}
5356
default:
54-
option.Option(command)
57+
err := option.Option(command)
58+
if err != nil {
59+
return nil, err
60+
}
5561
}
5662
}
5763

core/command/distinct.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func (d *Distinct) Encode(desc description.SelectedServer) (wiremessage.WireMess
4848
if option == nil {
4949
continue
5050
}
51-
option.Option(command)
51+
err := option.Option(command)
52+
if err != nil {
53+
return nil, err
54+
}
5255
}
5356

5457
return (&Command{DB: d.NS.DB, ReadPref: d.ReadPref, Command: command}).Encode(desc)

core/command/drop_collection.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (C) MongoDB, Inc. 2017-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package command
8+
9+
import (
10+
"context"
11+
12+
"github.com/mongodb/mongo-go-driver/bson"
13+
"github.com/mongodb/mongo-go-driver/core/description"
14+
"github.com/mongodb/mongo-go-driver/core/wiremessage"
15+
)
16+
17+
// DropCollection represents the drop command.
18+
//
19+
// The dropCollections command drops collection for a database.
20+
type DropCollection struct {
21+
DB string
22+
Collection string
23+
result bson.Reader
24+
err error
25+
}
26+
27+
// Encode will encode this command into a wire message for the given server description.
28+
func (di *DropCollection) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error) {
29+
cmd := bson.NewDocument(
30+
bson.EC.String("drop", di.Collection),
31+
)
32+
33+
return (&Command{DB: di.DB, Command: cmd, isWrite: true}).Encode(desc)
34+
}
35+
36+
// Decode will decode the wire message using the provided server description. Errors during decoding
37+
// are deferred until either the Result or Err methods are called.
38+
func (di *DropCollection) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropCollection {
39+
di.result, di.err = (&Command{}).Decode(desc, wm).Result()
40+
return di
41+
}
42+
43+
// Result returns the result of a decoded wire message and server description.
44+
func (di *DropCollection) Result() (bson.Reader, error) {
45+
if di.err != nil {
46+
return nil, di.err
47+
}
48+
return di.result, nil
49+
}
50+
51+
// Err returns the error set on this command.
52+
func (di *DropCollection) Err() error { return di.err }
53+
54+
// RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
55+
func (di *DropCollection) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (bson.Reader, error) {
56+
wm, err := di.Encode(desc)
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
err = rw.WriteWireMessage(ctx, wm)
62+
if err != nil {
63+
return nil, err
64+
}
65+
wm, err = rw.ReadWireMessage(ctx)
66+
if err != nil {
67+
return nil, err
68+
}
69+
return di.Decode(desc, wm).Result()
70+
}

core/command/find.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,25 @@ func (f *Find) Encode(desc description.SelectedServer) (wiremessage.WireMessage,
4343

4444
var limit int64
4545
var batchSize int32
46+
var err error
4647

4748
for _, option := range f.Opts {
4849
switch t := option.(type) {
4950
case nil:
5051
continue
5152
case options.OptLimit:
5253
limit = int64(t)
53-
option.Option(command)
54+
err = option.Option(command)
5455
case options.OptBatchSize:
5556
batchSize = int32(t)
56-
option.Option(command)
57+
err = option.Option(command)
5758
case options.OptProjection:
58-
t.IsFind().Option(command)
59+
err = t.IsFind().Option(command)
5960
default:
60-
option.Option(command)
61+
err = option.Option(command)
62+
}
63+
if err != nil {
64+
return nil, err
6165
}
6266
}
6367

0 commit comments

Comments
 (0)