summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-02-10 12:35:38 -0500
committerDwight <dmerriman@gmail.com>2009-02-10 12:35:38 -0500
commit4ab67f0e7ec75ac20c574b8cb986b18abe305e56 (patch)
treeb95fb692a6f4fde0f6035534ab8e9314e3f16c85
parentc8fb50b3f1a1a2a9fcd3d4d0f1c533ac30e8ffd8 (diff)
parent72d5a652fb9e785f66834b3db74426b32aa1cf23 (diff)
downloadmongo-4ab67f0e7ec75ac20c574b8cb986b18abe305e56.tar.gz
Merge branch 'master' of git.10gen.com:/data/gitroot/p
-rw-r--r--SConstruct56
-rw-r--r--client/dbclient.cpp2
-rw-r--r--client/gridfs.cpp5
-rw-r--r--db/jsobj.cpp7
-rw-r--r--db/jsobj.h78
-rw-r--r--dbtests/jsobjtests.cpp82
-rw-r--r--tools/Tool.h4
7 files changed, 206 insertions, 28 deletions
diff --git a/SConstruct b/SConstruct
index 712e60da88e..a7e111cc183 100644
--- a/SConstruct
+++ b/SConstruct
@@ -130,6 +130,7 @@ nix = False
useJavaHome = False
linux64 = False
darwin = False
+windows = False
force64 = not GetOption( "force64" ) is None
force32 = not GetOption( "force32" ) is None
release = not GetOption( "release" ) is None
@@ -138,7 +139,10 @@ noOptimization = not GetOption( "noOptimization" ) is None
noshell = not GetOption( "noshell" ) is None
platform = os.sys.platform
-processor = os.uname()[4]
+if "uname" in dir(os):
+ processor = os.uname()[4]
+else:
+ processor = "i386"
if force32:
processor = "i386"
@@ -218,7 +222,15 @@ elif "sunos5" == os.sys.platform:
env.Append( CPPDEFINES=[ "__linux__" ] )
elif "win32" == os.sys.platform:
+ windows = True
boostDir = "C:/Program Files/Boost/boost_1_35_0"
+
+ if not os.path.exists( boostDir ):
+ print( "can't find boost" )
+ Exit(1)
+
+ boostLibs = []
+
javaHome = findVersion( "C:/Program Files/java/" ,
[ "jdk" , "jdk1.6.0_10" ] )
winSDKHome = findVersion( "C:/Program Files/Microsoft SDKs/Windows/" ,
@@ -248,8 +260,11 @@ elif "win32" == os.sys.platform:
return False
return True
- commonFiles += filter( pcreFilter , Glob( "pcre-7.4/*.c" ) )
- commonFiles += filter( pcreFilter , Glob( "pcre-7.4/*.cc" ) )
+ pcreFiles = []
+ pcreFiles += filter( pcreFilter , Glob( "pcre-7.4/*.c" ) )
+ pcreFiles += filter( pcreFilter , Glob( "pcre-7.4/*.cc" ) )
+ commonFiles += pcreFiles
+ allClientFiles += pcreFiles
env.Append( LIBS=Split("ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib" ) )
@@ -461,7 +476,7 @@ env.Program( "mongofiles" , allToolFiles + [ "tools/files.cpp" ] )
env.Program( "mongos" , commonFiles + coreDbFiles + Glob( "dbgrid/*.cpp" ) )
# c++ library
-env.Library( "mongoclient" , allClientFiles )
+clientLibName = str( env.Library( "mongoclient" , allClientFiles )[0] )
env.Library( "mongotestfiles" , commonFiles + coreDbFiles + serverOnlyFiles )
clientTests = []
@@ -561,17 +576,23 @@ if distBuild:
# binaries
-env.Install( installDir + "/bin" , "mongodump" )
-env.Install( installDir + "/bin" , "mongorestore" )
+def installBinary( e , name ):
+ if windows:
+ name += ".exe"
+ env.Install( installDir + "/bin" , name )
+
+installBinary( env , "mongodump" )
+installBinary( env , "mongorestore" )
-env.Install( installDir + "/bin" , "mongoexport" )
-env.Install( installDir + "/bin" , "mongoimportjson" )
+installBinary( env , "mongoexport" )
+installBinary( env , "mongoimportjson" )
-env.Install( installDir + "/bin" , "mongofiles" )
+installBinary( env , "mongofiles" )
+
+installBinary( env , "mongod" )
-env.Install( installDir + "/bin" , "mongod" )
if not noshell:
- env.Install( installDir + "/bin" , "mongo" )
+ installBinary( env , "mongo" )
# NOTE: In some cases scons gets confused between installation targets and build
# dependencies. Here, we use InstallAs instead of Install to prevent such confusion
@@ -582,7 +603,7 @@ for id in [ "", "util/", "db/" , "client/" ]:
env.Install( installDir + "/include/mongo/" + id , Glob( id + "*.h" ) )
#lib
-env.Install( installDir + "/" + nixLibPrefix, "libmongoclient.a" )
+env.Install( installDir + "/" + nixLibPrefix, clientLibName )
env.Install( installDir + "/" + nixLibPrefix + "/mongo/jars" , Glob( "jars/*" ) )
#final alias
@@ -620,7 +641,6 @@ def s3push( localName , remoteName=None , remotePrefix="-latest" , fixName=True
import settings
s = simples3.S3Bucket( settings.bucket , settings.id , settings.key )
- un = os.uname()
if remoteName is None:
remoteName = localName
@@ -637,7 +657,7 @@ def s3push( localName , remoteName=None , remotePrefix="-latest" , fixName=True
if platformDir:
name = platform + "/" + name
- s.put( name , open( localName ).read() , acl="public-read" );
+ s.put( name , open( localName , "rb" ).read() , acl="public-read" );
print( "uploaded " + localName + " to http://s3.amazonaws.com/" + s.name + "/" + name )
def s3shellpush( env , target , source ):
@@ -649,9 +669,13 @@ env.AlwaysBuild( "s3shell" )
def s3dist( env , target , source ):
s3push( distFile , "mongo-db" )
-distFile = installDir + ".tgz"
env.Append( TARFLAGS=" -z " )
-env.Tar( distFile , installDir )
+if windows:
+ distFile = installDir + ".zip"
+ env.Zip( distFile , installDir )
+else:
+ distFile = installDir + ".tgz"
+ env.Tar( distFile , installDir )
env.Alias( "dist" , distFile )
env.Alias( "s3dist" , [ "install" , distFile ] , [ s3dist ] )
diff --git a/client/dbclient.cpp b/client/dbclient.cpp
index 1d5d5eb712a..1bc3337f48a 100644
--- a/client/dbclient.cpp
+++ b/client/dbclient.cpp
@@ -161,7 +161,7 @@ namespace mongo {
BSONObjBuilder b;
{
- b << "authenticate" << 1 << "nonce" << nonce << "user" << username << "key";
+ b << "authenticate" << 1 << "nonce" << nonce << "user" << username;
md5digest d;
{
md5_state_t st;
diff --git a/client/gridfs.cpp b/client/gridfs.cpp
index bd17894f7b2..92e8f79116d 100644
--- a/client/gridfs.cpp
+++ b/client/gridfs.cpp
@@ -1,9 +1,14 @@
// gridfs.cpp
+#include "../stdafx.h"
#include <fcntl.h>
#include "gridfs.h"
+#if defined(_WIN32)
+#include <io.h>
+#endif
+
#ifndef MIN
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
#endif
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index c1d87f00cf5..855e4e34dbf 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -1090,4 +1090,11 @@ namespace mongo {
*/
}
+ Labeler::Label GT( "$gt" );
+ Labeler::Label GTE( "$gte" );
+ Labeler::Label LT( "$lt" );
+ Labeler::Label LTE( "$lte" );
+ Labeler::Label NE( "$ne" );
+ Labeler::Label IN( "$in" );
+
} // namespace mongo
diff --git a/db/jsobj.h b/db/jsobj.h
index 78ea865559e..9337be5bcd7 100644
--- a/db/jsobj.h
+++ b/db/jsobj.h
@@ -36,6 +36,7 @@ namespace mongo {
class BSONObj;
class Record;
class BSONObjBuilder;
+ class BSONObjBuilderValueStream;
#pragma pack(1)
@@ -734,12 +735,36 @@ namespace mongo {
*/
#define BSON(x) (( BSONObjBuilder() << x ).obj())
+ class Labeler {
+ public:
+ struct Label {
+ Label( const char *l ) : l_( l ) {}
+ const char *l_;
+ };
+ Labeler( const Label &l, BSONObjBuilderValueStream *s ) : l_( l ), s_( s ) {}
+ template<class T>
+ BSONObjBuilder& operator<<( T value );
+ private:
+ const Label &l_;
+ BSONObjBuilderValueStream *s_;
+ };
+
+ extern Labeler::Label GT;
+ extern Labeler::Label GTE;
+ extern Labeler::Label LT;
+ extern Labeler::Label LTE;
+ extern Labeler::Label NE;
+ extern Labeler::Label IN;
+
class BSONObjBuilderValueStream {
public:
- BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder );
+ friend class Labeler;
+ BSONObjBuilderValueStream( BSONObjBuilder * builder );
template<class T>
BSONObjBuilder& operator<<( T value );
+
+ Labeler operator<<( const Labeler::Label &l );
/*
BSONObjBuilder& operator<<( const char * value );
BSONObjBuilder& operator<<( const string& v ) { return (*this << v.c_str()); }
@@ -748,11 +773,15 @@ namespace mongo {
BSONObjBuilder& operator<<( const unsigned long value ){ return (*this << (double)value); }
*/
+ void endField( const char *nextFieldName = 0 );
+ bool subobjStarted() const { return _fieldName; }
+
private:
const char * _fieldName;
BSONObjBuilder * _builder;
+ auto_ptr< BSONObjBuilder > _subobj;
};
-
+
/**
utility for creating a BSONObj
*/
@@ -989,15 +1018,23 @@ namespace mongo {
}
/** Stream oriented way to add field names and values. */
- BSONObjBuilderValueStream operator<<(const char * name ) {
- return BSONObjBuilderValueStream( name , this );
+ BSONObjBuilderValueStream &operator<<(const char * name ) {
+ if ( !s_.get() )
+ s_.reset( new BSONObjBuilderValueStream( this ) );
+ s_->endField( name );
+ return *s_;
}
/** Stream oriented way to add field names and values. */
- BSONObjBuilderValueStream operator<<( string name ) {
- return BSONObjBuilderValueStream( name.c_str() , this );
+ BSONObjBuilderValueStream &operator<<( string name ) {
+ return operator<<( name.c_str() );
}
+ Labeler operator<<( const Labeler::Label &l ) {
+ massert( "Value stream expected", s_.get() );
+ massert( "No subobject started", s_->subobjStarted() );
+ return *s_ << l;
+ }
private:
// Append the provided arr object as an array.
@@ -1008,6 +1045,8 @@ namespace mongo {
}
char* _done() {
+ if ( s_.get() )
+ s_->endField();
b.append((char) EOO);
char *data = b.buf();
*((int*)data) = b.len();
@@ -1015,6 +1054,7 @@ namespace mongo {
}
BufBuilder b;
+ auto_ptr< BSONObjBuilderValueStream > s_;
};
@@ -1191,15 +1231,35 @@ namespace mongo {
return false;
}
- inline BSONObjBuilderValueStream::BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder ) {
- _fieldName = fieldName;
+ inline BSONObjBuilderValueStream::BSONObjBuilderValueStream( BSONObjBuilder * builder ) {
+ _fieldName = 0;
_builder = builder;
+ _subobj.reset( new BSONObjBuilder() );
}
-
+
template<class T> inline
BSONObjBuilder& BSONObjBuilderValueStream::operator<<( T value ) {
_builder->append(_fieldName, value);
+ _fieldName = 0;
return *_builder;
}
+ inline Labeler BSONObjBuilderValueStream::operator<<( const Labeler::Label &l ) {
+ return Labeler( l, this );
+ }
+
+ inline void BSONObjBuilderValueStream::endField( const char *nextFieldName ) {
+ if ( _fieldName ) {
+ _builder->append( _fieldName, _subobj->done() );
+ _subobj.reset( new BSONObjBuilder() );
+ }
+ _fieldName = nextFieldName;
+ }
+
+ template<class T> inline
+ BSONObjBuilder& Labeler::operator<<( T value ) {
+ s_->_subobj->append( l_.l_, value );
+ return *s_->_builder;
+ }
+
} // namespace mongo
diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp
index 1199858f97c..e6f17de1c85 100644
--- a/dbtests/jsobjtests.cpp
+++ b/dbtests/jsobjtests.cpp
@@ -433,15 +433,87 @@ namespace JsobjTests {
OID a;
OID b;
- cout << endl;
a.init();
b.init( a.str() );
ASSERT( a == b );
}
};
- }
+ } // namespace OIDTests
+
+ namespace ValueStreamTests {
+
+ class LabelBase {
+ public:
+ void run() {
+ ASSERT( !expected().woCompare( actual() ) );
+ }
+ protected:
+ virtual BSONObj expected() = 0;
+ virtual BSONObj actual() = 0;
+ };
+
+ class LabelBasic : public LabelBase {
+ BSONObj expected() {
+ return BSON( "a" << ( BSON( "$gt" << 1 ) ) );
+ }
+ BSONObj actual() {
+ return BSON( "a" << GT << 1 );
+ }
+ };
+
+ class LabelShares : public LabelBase {
+ BSONObj expected() {
+ return BSON( "z" << "q" << "a" << ( BSON( "$gt" << 1 ) ) << "x" << "p" );
+ }
+ BSONObj actual() {
+ return BSON( "z" << "q" << "a" << GT << 1 << "x" << "p" );
+ }
+ };
+
+ class LabelDouble : public LabelBase {
+ BSONObj expected() {
+ return BSON( "a" << ( BSON( "$gt" << 1 << "$lte" << "x" ) ) );
+ }
+ BSONObj actual() {
+ return BSON( "a" << GT << 1 << LTE << "x" );
+ }
+ };
+
+ class LabelDoubleShares : public LabelBase {
+ BSONObj expected() {
+ return BSON( "z" << "q" << "a" << ( BSON( "$gt" << 1 << "$lte" << "x" ) ) << "x" << "p" );
+ }
+ BSONObj actual() {
+ return BSON( "z" << "q" << "a" << GT << 1 << LTE << "x" << "x" << "p" );
+ }
+ };
+ class LabelMulti : public LabelBase {
+ BSONObj expected() {
+ return BSON( "z" << "q"
+ << "a" << BSON( "$gt" << 1 << "$lte" << "x" )
+ << "b" << BSON( "$ne" << 1 << "$ne" << "f" << "$ne" << 22.3 )
+ << "x" << "p" );
+ }
+ BSONObj actual() {
+ return BSON( "z" << "q"
+ << "a" << GT << 1 << LTE << "x"
+ << "b" << NE << 1 << NE << "f" << NE << 22.3
+ << "x" << "p" );
+ }
+ };
+
+ class Unallowed {
+ public:
+ void run() {
+ ASSERT_EXCEPTION( BSON( GT << 4 ), MsgAssertionException );
+ ASSERT_EXCEPTION( BSON( "a" << 1 << GT << 4 ), MsgAssertionException );
+ }
+ };
+
+ } // namespace ValueStreamTests
+
class All : public UnitTest::Suite {
public:
All() {
@@ -487,6 +559,12 @@ namespace JsobjTests {
add< BSONObjTests::Validation::Fuzz >( .001 );
add< OIDTests::init1 >();
add< OIDTests::initParse1 >();
+ add< ValueStreamTests::LabelBasic >();
+ add< ValueStreamTests::LabelShares >();
+ add< ValueStreamTests::LabelDouble >();
+ add< ValueStreamTests::LabelDoubleShares >();
+ add< ValueStreamTests::LabelMulti >();
+ add< ValueStreamTests::Unallowed >();
}
};
diff --git a/tools/Tool.h b/tools/Tool.h
index 772301fbc29..8f7b2fa76c6 100644
--- a/tools/Tool.h
+++ b/tools/Tool.h
@@ -6,6 +6,10 @@
#include <boost/program_options.hpp>
+#if defined(_WIN32)
+#include <io.h>
+#endif
+
#include "client/dbclient.h"
using std::string;