Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bsondump/main/bsondump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
opts, err := bsondump.ParseOptions(os.Args[1:], VersionStr, GitCommit)
if err != nil {
log.Logvf(log.Always, "%v", err)
log.Logvf(log.Always, util.ShortUsage("bsondump"))
log.Logv(log.Always, util.ShortUsage("bsondump"))
os.Exit(util.ExitFailure)
}

Expand Down
4 changes: 2 additions & 2 deletions buildscript/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
// the new config file syntax did not seem trivial.
eslintVersion = "8.57.0"
gitHubCodeownersVersion = "0.2.1"
golangCILintVersion = "2.3.0"
golangCILintVersion = "2.5.0"
golinesVersion = "0.12.2"
gosecVersion = "2.20.0"
gosecVersion = "2.22.10"
preciousVersion = "0.7.3"
ubiVersion = "0.4.2"
prettierVersion = "3.4.2"
Expand Down
7 changes: 6 additions & 1 deletion common/archive/prelude.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"sync/atomic"

"github.com/ccoveille/go-safecast"
"github.com/mongodb/mongo-tools/common/intents"
"github.com/mongodb/mongo-tools/common/log"
"github.com/mongodb/mongo-tools/common/util"
Expand Down Expand Up @@ -95,12 +96,16 @@ func NewPrelude(
concurrentColls int,
serverVersion, toolVersion string,
) (*Prelude, error) {
concurrentCollsi32, err := safecast.ToInt32(concurrentColls)
if err != nil {
return nil, fmt.Errorf("concurrentColls overflows when cast to int32")
}
prelude := Prelude{
Header: &Header{
FormatVersion: archiveFormatVersion,
ServerVersion: serverVersion,
ToolVersion: toolVersion,
ConcurrentCollections: int32(concurrentColls),
ConcurrentCollections: concurrentCollsi32,
},
NamespaceMetadatasByDB: make(map[string][]*CollectionMetadata, 0),
}
Expand Down
3 changes: 2 additions & 1 deletion common/bsonutil/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"time"

"github.com/ccoveille/go-safecast"
"github.com/mongodb/mongo-tools/common/json"
"github.com/mongodb/mongo-tools/common/util"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -319,7 +320,7 @@ func GetBSONValueAsLegacyExtJSON(x interface{}) (interface{}, error) {
return v, nil // require no conversion

case int:
return json.NumberInt(v), nil
return safecast.ToInt32(v)

case primitive.ObjectID: // ObjectId
return json.ObjectId(v.Hex()), nil
Expand Down
3 changes: 2 additions & 1 deletion common/db/bson_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"

"github.com/ccoveille/go-safecast"
"go.mongodb.org/mongo-driver/bson"
)

Expand Down Expand Up @@ -103,7 +104,7 @@ func (bs *BSONSource) LoadNext() []byte {
return nil
}

bsonSize := int32(
bsonSize, _ := safecast.ToInt32(
(uint32(into[0]) << 0) |
(uint32(into[1]) << 8) |
(uint32(into[2]) << 16) |
Expand Down
9 changes: 7 additions & 2 deletions common/json/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"unicode/utf16"
"unicode/utf8"

"github.com/ccoveille/go-safecast"
"go.mongodb.org/mongo-driver/bson"
)

Expand Down Expand Up @@ -237,8 +238,12 @@ func (n Number) Float64() (float64, error) {

// Int32 returns the number as an int32.
func (n Number) Int32() (int32, error) {
x, err := n.Int64()
return int32(x), err
n2, err := n.Int64()
if err != nil {
return int32(0), err
}
x, err := safecast.ToInt32(n2)
return x, err
}

// Int64 returns the number as an int64.
Expand Down
6 changes: 3 additions & 3 deletions common/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,20 +564,20 @@ func LogSensitiveOptionWarnings(args []string) {

// Log a message for --password, if specified.
if tempOpts.Password != "" {
log.Logvf(log.Always, passwordMsg)
log.Logv(log.Always, passwordMsg)
}

// Log a message for --uri or a positional connection string, if either is specified.
uri := tempOpts.ConnectionString
if uri != "" {
if cs, err := connstring.Parse(uri); err == nil && cs.Password != "" {
log.Logvf(log.Always, uriMsg)
log.Logv(log.Always, uriMsg)
}
}

// Log a message for --sslPEMKeyPassword, if specified.
if tempOpts.SSLPEMKeyPassword != "" {
log.Logvf(log.Always, sslMsg)
log.Logv(log.Always, sslMsg)
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/options/options_fp_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package options

// EnableFailpoints removes the failpoints options
// EnableFailpoints removes the failpoints options.
func EnableFailpoints(opts *ToolOptions) {
opt := opts.FindOptionByLongName("failpoints")
opt.LongName = ""
Expand Down
10 changes: 5 additions & 5 deletions cyclonedx.sbom.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,17 +800,17 @@
"version": "v2.4.0"
},
{
"bom-ref": "pkg:golang/std@go1.23.12",
"bom-ref": "pkg:golang/std@go1.25.2",
"externalReferences": [
{
"type": "website",
"url": "https://pkg.go.dev/None/std@go1.23.12"
"url": "https://pkg.go.dev/None/std@go1.25.2"
}
],
"name": "std",
"purl": "pkg:golang/std@go1.23.12",
"purl": "pkg:golang/std@go1.25.2",
"type": "library",
"version": "go1.23.12"
"version": "go1.25.2"
}
],
"dependencies": [
Expand Down Expand Up @@ -911,7 +911,7 @@
"ref": "pkg:golang/gopkg.in/[email protected]"
},
{
"ref": "pkg:golang/std@go1.23.12"
"ref": "pkg:golang/std@go1.25.2"
}
],
"metadata": {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mongodb/mongo-tools

go 1.23.0
go 1.25.0

toolchain go1.23.8
toolchain go1.25.2

require (
github.com/craiggwilson/goke v0.0.0-20240206162536-b1c58122d943
Expand Down Expand Up @@ -59,6 +59,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.34.0 // indirect
github.com/aws/smithy-go v1.22.4 // indirect
github.com/ccoveille/go-safecast v1.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.34.0 h1:NFOJ/NXEGV4Rq//71Hs1jC/NvPs1
github.com/aws/aws-sdk-go-v2/service/sts v1.34.0/go.mod h1:7ph2tGpfQvwzgistp2+zga9f+bCjlQJPkPUmMgDSD7w=
github.com/aws/smithy-go v1.22.4 h1:uqXzVZNuNexwc/xrh6Tb56u89WDlJY6HS+KC0S4QSjw=
github.com/aws/smithy-go v1.22.4/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
github.com/ccoveille/go-safecast v1.7.0 h1:i+0eldPFBeXCTARGyocNS6BNRomquA/GhTZVNEtaIXI=
github.com/ccoveille/go-safecast v1.7.0/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
Expand Down
2 changes: 1 addition & 1 deletion mongodump/main/mongodump.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
opts, err := mongodump.ParseOptions(os.Args[1:], VersionStr, GitCommit)
if err != nil {
log.Logvf(log.Always, "error parsing command line options: %s", err.Error())
log.Logvf(log.Always, util.ShortUsage("mongodump"))
log.Logv(log.Always, util.ShortUsage("mongodump"))
os.Exit(util.ExitFailure)
}

Expand Down
4 changes: 2 additions & 2 deletions mongodump_passthrough/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ functions:
# XXX - Since mise is scoped to the Mongosync repo root, we cannot easily use it to build things
# outside that root. It'd be nice if the migration-verifier also used mise too, but for now this
# works okay.
PATH=$PATH:$HOME:/opt/golang/go1.23/bin
GOROOT=/opt/golang/go1.23
PATH=$PATH:$HOME:/opt/golang/go1.25/bin
GOROOT=/opt/golang/go1.25
./build.sh
# upload the compiled verifier to S3.
- command: s3.put
Expand Down
2 changes: 1 addition & 1 deletion mongoexport/main/mongoexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
opts, err := mongoexport.ParseOptions(os.Args[1:], VersionStr, GitCommit)
if err != nil {
log.Logvf(log.Always, "error parsing command line options: %v", err)
log.Logvf(log.Always, util.ShortUsage("mongoexport"))
log.Logv(log.Always, util.ShortUsage("mongoexport"))
os.Exit(util.ExitFailure)
}

Expand Down
2 changes: 1 addition & 1 deletion mongofiles/main/mongofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
if err != nil {
log.Logv(log.Always, err.Error())
if setupErr, ok := err.(util.SetupError); ok && setupErr.Message != "" {
log.Logvf(log.Always, setupErr.Message)
log.Logv(log.Always, setupErr.Message)
}
os.Exit(util.ExitFailure)
}
Expand Down
4 changes: 2 additions & 2 deletions mongofiles/mongofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (mf *MongoFiles) handleDeleteID() error {
if err := file.Delete(); err != nil {
return err
}
log.Logvf(log.Always, fmt.Sprintf("successfully deleted file with _id %v from GridFS", mf.Id))
log.Logv(log.Always, fmt.Sprintf("successfully deleted file with _id %v from GridFS", mf.Id))

return nil
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func (mf *MongoFiles) writeGFSFileToLocal(gridFile *gfsFile) (err error) {
return fmt.Errorf("error while writing Data into local file '%v': %v", localFileName, err)
}

log.Logvf(log.Always, fmt.Sprintf("finished writing to %s\n", localFileName))
log.Logv(log.Always, fmt.Sprintf("finished writing to %s\n", localFileName))
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions mongoimport/main/mongoimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
opts, err := mongoimport.ParseOptions(os.Args[1:], VersionStr, GitCommit)
if err != nil {
log.Logvf(log.Always, "error parsing command line options: %v", err)
log.Logvf(log.Always, util.ShortUsage("mongoimport"))
log.Logv(log.Always, util.ShortUsage("mongoimport"))
os.Exit(util.ExitFailure)
}

Expand All @@ -43,7 +43,7 @@ func main() {

m, err := mongoimport.New(opts)
if err != nil {
log.Logvf(log.Always, err.Error())
log.Logv(log.Always, err.Error())
os.Exit(util.ExitFailure)
}
defer m.Close()
Expand Down
17 changes: 7 additions & 10 deletions mongoimport/mongoimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sync"
"sync/atomic"

"github.com/ccoveille/go-safecast"
"github.com/mongodb/mongo-tools/common/db"
"github.com/mongodb/mongo-tools/common/log"
"github.com/mongodb/mongo-tools/common/options"
Expand Down Expand Up @@ -488,18 +489,14 @@ readLoop:
}

func (imp *MongoImport) updateCounts(result *mongo.BulkWriteResult, err error) {
i, _ := safecast.ToUint64(result.InsertedCount)
m, _ := safecast.ToUint64(result.ModifiedCount)
u, _ := safecast.ToUint64(result.UpsertedCount)
d, _ := safecast.ToUint64(result.DeletedCount)

if result != nil {
atomic.AddUint64(
&imp.processedCount,
uint64(
result.InsertedCount,
)+uint64(
result.ModifiedCount,
)+uint64(
result.UpsertedCount,
)+uint64(
result.DeletedCount,
),
&imp.processedCount, i+m+u+d,
)
}
if bwe, ok := err.(mongo.BulkWriteException); ok {
Expand Down
4 changes: 2 additions & 2 deletions mongorestore/main/mongorestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {

if err != nil {
log.Logvf(log.Always, "error parsing command line options: %s", err.Error())
log.Logvf(log.Always, util.ShortUsage("mongorestore"))
log.Logv(log.Always, util.ShortUsage("mongorestore"))
os.Exit(util.ExitFailure)
}

Expand All @@ -41,7 +41,7 @@ func main() {

restore, err := mongorestore.New(opts)
if err != nil {
log.Logvf(log.Always, err.Error())
log.Logv(log.Always, err.Error())
os.Exit(util.ExitFailure)
}
defer restore.Close()
Expand Down
8 changes: 7 additions & 1 deletion mongorestore/oplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"
"strings"

"github.com/ccoveille/go-safecast"
"github.com/mongodb/mongo-tools/common/bsonutil"
"github.com/mongodb/mongo-tools/common/db"
"github.com/mongodb/mongo-tools/common/dumprestore"
Expand Down Expand Up @@ -467,8 +468,13 @@ func ParseTimestampFlag(ts string) (primitive.Timestamp, error) {
increment = 0
}
}
t, err := safecast.ToUint32(seconds)
if err != nil {
return primitive.Timestamp{}, err
}
i, err2 := safecast.ToUint32(increment)

return primitive.Timestamp{T: uint32(seconds), I: uint32(increment)}, nil
return primitive.Timestamp{T: t, I: i}, err2
}

// Server versions 3.6.0-3.6.8 and 4.0.0-4.0.2 require a 'ui' field
Expand Down
2 changes: 1 addition & 1 deletion mongostat/main/mongostat.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
opts, err := mongostat.ParseOptions(os.Args[1:], VersionStr, GitCommit)
if err != nil {
log.Logvf(log.Always, "error parsing command line options: %s", err.Error())
log.Logvf(log.Always, util.ShortUsage("mongostat"))
log.Logv(log.Always, util.ShortUsage("mongostat"))
os.Exit(util.ExitFailure)
}

Expand Down
2 changes: 1 addition & 1 deletion mongotop/main/mongotop.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
opts, err := mongotop.ParseOptions(os.Args[1:], VersionStr, GitCommit)
if err != nil {
log.Logvf(log.Always, "error parsing command line options: %s", err.Error())
log.Logvf(log.Always, util.ShortUsage("mongotop"))
log.Logv(log.Always, util.ShortUsage("mongotop"))
os.Exit(util.ExitFailure)
}

Expand Down
2 changes: 1 addition & 1 deletion release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func buildDeb() {
for _, path := range md5sumsOrder {
md5sum, ok := md5sums[path]
if !ok {
log.Fatalf("could not find md5sum for " + path)
log.Fatalf("could not find md5sum for %#q", path)
}
_, err = f.WriteString(md5sum + " ")
check(err, "write md5sum to md5sums")
Expand Down
6 changes: 3 additions & 3 deletions set_goenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ set_goenv() {
UNAME_S=$(PATH="/usr/bin:/bin" uname -s)
case $UNAME_S in
CYGWIN*)
PREF_GOROOT="c:/golang/go1.23"
PREF_PATH="/cygdrive/c/golang/go1.22/bin:/cygdrive/c/mingw-w64/x86_64-4.9.1-posix-seh-rt_v3-rev1/mingw64/bin:$PATH"
PREF_GOROOT="c:/golang/go1.25"
PREF_PATH="/cygdrive/c/golang/go1.25/bin:/cygdrive/c/mingw-w64/x86_64-4.9.1-posix-seh-rt_v3-rev1/mingw64/bin:$PATH"
;;
*)
PREF_GOROOT="/opt/golang/go1.23"
PREF_GOROOT="/opt/golang/go1.25"
PREF_PATH="$PREF_GOROOT/bin:$PATH"
;;
esac
Expand Down
Loading