summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2013-07-17 16:21:49 +0200
committerAntonin Kral <a.kral@bobek.cz>2013-07-17 16:21:49 +0200
commite3904bf97e74cbbe5dde6b3abc3e797ad7d26b5d (patch)
treef2d76fa86bfce0e897a616e02551bdd7d9913682 /src/mongo/shell
parentbef4346b845150d5318fd7a0acb43554f0d40a06 (diff)
Imported Upstream version 2.4.5upstream/2.4.5
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/createCPPfromJavaScriptFiles.js10
-rw-r--r--src/mongo/shell/db.js6
-rw-r--r--src/mongo/shell/replsettest.js8
-rw-r--r--src/mongo/shell/shell_utils.cpp14
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp15
-rw-r--r--src/mongo/shell/types.js28
6 files changed, 59 insertions, 22 deletions
diff --git a/src/mongo/shell/createCPPfromJavaScriptFiles.js b/src/mongo/shell/createCPPfromJavaScriptFiles.js
index 32d2fbbd044..c77c56817e6 100644
--- a/src/mongo/shell/createCPPfromJavaScriptFiles.js
+++ b/src/mongo/shell/createCPPfromJavaScriptFiles.js
@@ -24,15 +24,7 @@
var whitespace = " \t";
function cppEscape( s ) {
- for ( var i = 0, len = s.length; i < len; ++i ) {
- if ( whitespace.indexOf( s.charAt( i ) ) === -1 ) {
- s = s.substring( i );
- break;
- }
- }
- if ( i == len )
- return "";
- for ( i = s.length - 1; i >= 0; --i ) {
+ for ( var i = s.length - 1; i >= 0; --i ) {
if ( whitespace.indexOf( s.charAt( i ) ) === -1 ) {
s = s.substr( 0, i + 1 );
break;
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index c343f9b6615..a41172ecf1e 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -269,11 +269,15 @@ DB.prototype.auth = function() {
*/
DB.prototype.createCollection = function(name, opt) {
var options = opt || {};
- var cmd = { create: name, capped: options.capped, size: options.size };
+ var cmd = { create: name };
if (options.max != undefined)
cmd.max = options.max;
if (options.autoIndexId != undefined)
cmd.autoIndexId = options.autoIndexId;
+ if (options.capped != undefined)
+ cmd.capped = options.capped;
+ if (options.size != undefined)
+ cmd.size = options.size;
var res = this._dbCommand(cmd);
return res;
}
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 1ca47130df7..a9c8c36b050 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -380,7 +380,7 @@ ReplSetTest.awaitRSClientHosts = function( conn, host, hostOk, rs ) {
}
ReplSetTest.prototype.awaitSecondaryNodes = function( timeout ) {
- this.getMaster(); // Wait for a primary to be selected.
+ this.getMaster(timeout); // Wait for a primary to be selected.
var tmo = timeout || 60000;
var replTest = this;
assert.soon(
@@ -469,17 +469,17 @@ ReplSetTest.prototype.initiate = function( cfg , initCmd , timeout ) {
var config = cfg || this.getReplSetConfig();
var cmd = {};
var cmdKey = initCmd || 'replSetInitiate';
- var timeout = timeout || 30000;
+ var tmo = timeout || 30000;
cmd[cmdKey] = config;
printjson(cmd);
- jsTest.attempt({context:this, timeout: timeout, desc: "Initiate replica set"}, function() {
+ jsTest.attempt({context:this, timeout: tmo, desc: "Initiate replica set"}, function() {
var result = master.runCommand(cmd);
printjson(result);
return result['ok'] == 1;
});
- this.awaitSecondaryNodes();
+ this.awaitSecondaryNodes(timeout);
// Setup authentication if running test with authentication
if (jsTestOptions().keyFile && !this.keyFile) {
diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp
index dce193c1a44..9c48487d314 100644
--- a/src/mongo/shell/shell_utils.cpp
+++ b/src/mongo/shell/shell_utils.cpp
@@ -18,11 +18,13 @@
#include "pch.h"
#include "mongo/shell/shell_utils.h"
+
+#include "mongo/client/dbclientinterface.h"
+#include "mongo/scripting/engine.h"
#include "mongo/shell/shell_utils_extended.h"
#include "mongo/shell/shell_utils_launcher.h"
#include "mongo/util/processinfo.h"
-#include "mongo/client/dbclientinterface.h"
-#include "mongo/scripting/engine.h"
+#include "mongo/util/version.h"
namespace mongo {
@@ -124,6 +126,13 @@ namespace mongo {
#endif
}
+ BSONObj getBuildInfo(const BSONObj& a, void* data) {
+ uassert( 16822, "getBuildInfo accepts no arguments", a.nFields() == 0 );
+ BSONObjBuilder b;
+ appendBuildInfo(b);
+ return BSON( "" << b.done() );
+ }
+
BSONObj interpreterVersion(const BSONObj& a, void* data) {
uassert( 16453, "interpreterVersion accepts no arguments", a.nFields() == 0 );
return BSON( "" << globalScriptEngine->getInterpreterVersionString() );
@@ -136,6 +145,7 @@ namespace mongo {
scope.injectNative( "_rand" , JSRand );
scope.injectNative( "_isWindows" , isWindows );
scope.injectNative( "interpreterVersion", interpreterVersion );
+ scope.injectNative( "getBuildInfo", getBuildInfo );
#ifndef MONGO_SAFE_SHELL
//can't launch programs
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index cb940dce14e..625efa83e1c 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -299,8 +299,10 @@ namespace mongo {
break;
}
if ( last != buf ) {
- strcpy( temp, last );
- strcpy( buf, temp );
+ strncpy( temp, last, bufSize );
+ temp[ bufSize-1 ] = '\0';
+ strncpy( buf, temp, bufSize );
+ buf[ bufSize-1 ] = '\0';
}
else {
verify( strlen( buf ) < bufSize );
@@ -556,6 +558,14 @@ namespace mongo {
return undefinedReturn;
}
+ BSONObj PathExists( const BSONObj &a, void* data ) {
+ verify( a.nFields() == 1 );
+ string path = a.firstElement().valuestrsafe();
+ verify( !path.empty() );
+ bool exists = boost::filesystem::exists(path);
+ return BSON( string( "" ) << exists );
+ }
+
void copyDir( const boost::filesystem::path &from, const boost::filesystem::path &to ) {
boost::filesystem::directory_iterator end;
boost::filesystem::directory_iterator i( from );
@@ -773,6 +783,7 @@ namespace mongo {
scope.injectNative( "waitProgram" , WaitProgram );
scope.injectNative( "checkProgram" , CheckProgram );
scope.injectNative( "resetDbpath", ResetDbpath );
+ scope.injectNative( "pathExists", PathExists );
scope.injectNative( "copyDbpath", CopyDbpath );
}
}
diff --git a/src/mongo/shell/types.js b/src/mongo/shell/types.js
index 3c5cfa8622b..9a63c05022b 100644
--- a/src/mongo/shell/types.js
+++ b/src/mongo/shell/types.js
@@ -68,9 +68,29 @@ ISODate = function(isoDateStr){
var date = parseInt(res[3],10) || 0;
var hour = parseInt(res[5],10) || 0;
var min = parseInt(res[7],10) || 0;
- var sec = parseFloat(res[9]) || 0;
- var ms = Math.round((sec%1) * 1000)
- sec -= ms/1000
+ var sec = parseInt((res[9] && res[9].substr(0,2)),10) || 0;
+ var ms = Math.round((parseFloat(res[10]) || 0) * 1000);
+ if (ms == 1000) {
+ ms = 0;
+ ++sec;
+ }
+ if (sec == 60) {
+ sec = 0;
+ ++min;
+ }
+ if (min == 60) {
+ min = 0;
+ ++hour;
+ }
+ if (hour == 24) {
+ hour = 0; // the day wrapped, let JavaScript figure out the rest
+ var tempTime = Date.UTC(year, month, date, hour, min, sec, ms);
+ tempTime += 24 * 60 * 60 * 1000; // milliseconds in a day
+ var tempDate = new Date(tempTime);
+ year = tempDate.getUTCFullYear();
+ month = tempDate.getUTCMonth();
+ date = tempDate.getUTCDate();
+ }
var time = Date.UTC(year, month, date, hour, min, sec, ms);
@@ -539,7 +559,7 @@ tojson = function(x, indent, nolint){
case "object":{
var s = tojsonObject(x, indent, nolint);
if ((nolint == null || nolint == true) && s.length < 80 && (indent == null || indent.length == 0)){
- s = s.replace(/[\s\r\n ]+/gm, " ");
+ s = s.replace(/[\t\r\n]+/gm, " ");
}
return s;
}