<commit_before>var files = require('../fs/files.js');
var utils = require('../utils/utils.js');
var mongoExitCodes = require('../utils/mongo-exit-codes.js');
var fiberHelpers = require('../utils/fiber-helpers.js');
var runLog = require('./run-log.js');
var child_process = require('child_process');

var _ = require('underscore');
var isopackets = require('../tool-env/isopackets.js');

// Given a Mongo URL, open an interative Mongo shell on this terminal
// on that database.
var runMongoShell = function (url) {
  var mongoPath = files.pathJoin(files.getDevBundle(), 'mongodb', 'bin', 'mongo');
  // XXX mongo URLs are not real URLs (notably, the comma-separation for
  // multiple hosts). We've had a little better luck using the mongodb-uri npm
  // package.
  var mongoUrl = require('url').parse(url);
  var auth = mongoUrl.auth && mongoUrl.auth.split(':');
  var ssl = require('querystring').parse(mongoUrl.query).ssl === "true";

  var args = [];
  if (ssl) {
    args.push('--ssl');
  }
  if (auth) {
    args.push('-u', auth[0]);
  }
  if (auth) {
    args.push('-p', auth[1]);
  }
  args.push(mongoUrl.hostname + ':' + mongoUrl.port + mongoUrl.pathname);

  child_process.spawn(files.convertToOSPath(mongoPath),
    args, { stdio: 'inherit' });
};

// Start mongod with a dummy replSet and wait for it to listen.
var spawnMongod = function (mongodPath, port, dbPath, replSetName) {
  var child_process = require('child_process');

  mongodPath = files.convertToOSPath(mongodPath);
  dbPath = files.convertToOSPath(dbPath);

  return child_process.spawn(mongodPath, [
      // nb: cli-test.sh and findMongoPids make strong assumptions about the
      // order of the arguments! Check them before changing any arguments.
      '--bind_ip', '127.0.0.1',
      '--smallfiles',
      '--port', port,
      '--dbpath', dbPath,
      // Use an 8MB oplog rather than 256MB. Uses less space on disk and
      // initializes faster. (Not recommended for production!)
      '--oplogSize', '8',
      '--replSet', replSetName
  ], {
    // Apparently in some contexts, Mongo crashes if your locale isn't set up
    // right. I wasn't able to reproduce it, but many people on #4019
    // were. Let's default a couple environment variables to English UTF-8 if
    // they aren't set already. If these few aren't good enough, we'll at least
    // detect the locale error and print a link to #4019 (look for
    // `detectedErrors.badLocale` below).
    env: _.extend({
      LANG: 'en_US.UTF-8',
      LC_ALL: 'en_US.UTF-8'
    }, process.env)
  });
};

// Find all running Mongo processes that were started by this program
// (even by other simultaneous runs of this program). If passed,
// dbDir and port act as filters on the list of running mongos.
//
// Yields. Returns an array of objects with keys pid, port, dbDir.
var findMongoPids;
if (process.platform === 'win32') {
  // Windows doesn't have a ps equivalent that (reliably) includes the command
  // line, so approximate using the combined output of tasklist and netstat.
  findMongoPids = function (dbDir_unused, port) {
    var promise = fiberHelpers.makeFulfillablePromise();

    child_process.exec('tasklist /fi "IMAGENAME eq mongod.exe"',
      function (error, stdout, stderr) {
        if (error) {
          var additionalInfo = JSON.stringify(error);
          if (error.code === 'ENOENT') {
            additionalInfo = "tasklist wasn't found on your system, it usually can be found at C:\\Windows\\System32\\.";
          }
          promise.reject(
            new Error("Couldn't run tasklist.exe: " + additionalInfo)
          );
          return;
        } else {
          // Find the pids of all mongod processes<commit_msg>Run mongod with mmapv1 instead of wiredTiger on Windows.<commit_after>var files = require('../fs/files.js');
var utils = require('../utils/utils.js');
var mongoExitCodes = require('../utils/mongo-exit-codes.js');
var fiberHelpers = require('../utils/fiber-helpers.js');
var runLog = require('./run-log.js');
var child_process = require('child_process');

var _ = require('underscore');
var isopackets = require('../tool-env/isopackets.js');

// Given a Mongo URL, open an interative Mongo shell on this terminal
// on that database.
var runMongoShell = function (url) {
  var mongoPath = files.pathJoin(files.getDevBundle(), 'mongodb', 'bin', 'mongo');
  // XXX mongo URLs are not real URLs (notably, the comma-separation for
  // multiple hosts). We've had a little better luck using the mongodb-uri npm
  // package.
  var mongoUrl = require('url').parse(url);
  var auth = mongoUrl.auth && mongoUrl.auth.split(':');
  var ssl = require('querystring').parse(mongoUrl.query).ssl === "true";

  var args = [];
  if (ssl) {
    args.push('--ssl');
  }
  if (auth) {
    args.push('-u', auth[0]);
  }
  if (auth) {
    args.push('-p', auth[1]);
  }
  args.push(mongoUrl.hostname + ':' + mongoUrl.port + mongoUrl.pathname);

  child_process.spawn(files.convertToOSPath(mongoPath),
    args, { stdio: 'inherit' });
};

// Start mongod with a dummy replSet and wait for it to listen.
function spawnMongod(mongodPath, port, dbPath, replSetName) {
  const child_process = require('child_process');

  mongodPath = files.convertToOSPath(mongodPath);
  dbPath = files.convertToOSPath(dbPath);

  const args = [
    // nb: cli-test.sh and findMongoPids make strong assumptions about the
    // order of the arguments! Check them before changing any arguments.
    '--bind_ip', '127.0.0.1',
    '--smallfiles',
    '--port', port,
    '--dbpath', dbPath,
    // Use an 8MB oplog rather than 256MB. Uses less space on disk and
    // initializes faster. (Not recommended for production!)
    '--oplogSize', '8',
    '--replSet', replSetName
  ];

  if (process.platform === "win32") {
    args.push('--storageEngine', 'mmapv1');
  }

  return child_process.spawn(mongodPath, args, {
    // Apparently in some contexts, Mongo crashes if your locale isn't set up
    // right. I wasn't able to reproduce it, but many people on #4019
    // were. Let's default a couple environment variables to English UTF-8 if
    // they aren't set already. If these few aren't good enough, we'll at least
    // detect the locale error and print a link to #4019 (look for
    // `detectedErrors.badLocale` below).
    env: _.extend({
      LANG: 'en_US.UTF-8',
      LC_ALL: 'en_US.UTF-8'
    }, process.env)
  });
}

// Find all running Mongo processes that were started by this program
// (even by other simultaneous runs of this program). If passed,
// dbDir and port act as filters on the list of running mongos.
//
// Yields. Returns an array of objects with keys pid, port, dbDir.
var findMongoPids;
if (process.platform === 'win32') {
  // Windows doesn't have a ps equivalent that (reliably) includes the command
  // line, so approximate using the combined output of tasklist and netstat.
  findMongoPids = function (dbDir_unused, port) {
    var promise = fiberHelpers.makeFulfillablePromise();

    child_process.exec('tasklist /fi "IMAGENAME eq mongod.exe"',
      function (error, stdout, stderr) {
        if (error) {
          var additionalInfo = JSON.stringify(error);
          if (error.code === 'ENOENT') {
            additionalInfo = "tasklist wasn't found on your system, it usually can be found at C:\\Windows\\System32\\.";
          }
          promise.reject(
            new Error("Couldn't run tasklist.exe: " + additionalInfo)
          );
          return;
        } else {
          // Find the pids of all mongod processes
{'fraction_non_alphanumeric': 0.13439575033200532, 'fraction_numerical': 0.00796812749003984, 'mean_word_length': 3.042404723564144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6929841', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2327, 'n_words': 759}