<commit_before>/**
 * @file
 * Control flow for the Kalabox installer.
 */

// Dependencies:
var flow = require('nue').flow,
    as = require('nue').as,
    parallel = require('nue').parallel,
    installUtils = require('./install-utils'),
    exec = require('child_process').exec,
    url = require('url'),
    fs = require('fs'),
    box = require('../box'),
    logger = require('../../logger'),
    taskManager = require('../utils/task-runner/task-manager'),
    config = require('../../config'),
    sudoRunner = require('../utils/task-runner/sudo-runner');

// "Constants":
var VBOX_URL = 'http://files.kalamuna.com/virtualbox-macosx-4.2.8.dmg',
    VBOX_VERSION = '4.2.8',
    TEMP_DIR = '/tmp/',
    VAGRANT_VERSION = config.get('VAGRANT_VERSION'),
    VAGRANT_URL = 'http://files.kalamuna.com/vagrant-macosx-' + VAGRANT_VERSION + '.dmg',
    VAGRANT_PLUGINS = config.get('VAGRANT_PLUGINS'),
    KALABOX_DIR = config.get('KALABOX_DIR'),
    KALABOX64_URL = 'http://files.kalamuna.com/kalabox64.box',
    KALABOX64_FILENAME = 'kalabox64.box',
    KALASTACK_DIR = config.get('KALASTACK_DIR'),
    KALASTACK_URL = config.get('KALASTACK_URL'),
    KALASTACK_FILENAME = 'kalastack.tar.gz';

// "Variables":
var socket;

// Installer file info:
var vboxUrlParsed = url.parse(VBOX_URL);
vboxUrlParsed.packageLocation = '/Volumes/VirtualBox/VirtualBox.pkg';
var vagrantUrlParsed = url.parse(VAGRANT_URL);
vagrantUrlParsed.packageLocation = '/Volumes/Vagrant/Vagrant.pkg';

// Helper functions:
function downloadAndReport(url, destination, callback) {
  // Download file via the utils.
  installUtils.downloadFile(url, destination, function(error, percentDone) {
    if (percentDone < 100) {
      // Notify client of progress.
      io.sockets.emit('installer', { complete: percentDone });
    }
    else {
      if (error) {
        installUtils.checkInternet(function(hasInternet) {
          if (!hasInternet) {
            error.message = 'No internet';
            io.sockets.emit('noInternet');
          }
          callback(error);
        });
      }
      else {
        callback(null);
      }
    }
  });
}

function sendMessage(message) {
  io.sockets.emit('installer', { message: message });
}

var installPermission = flow('installPermission')(
  // Activate the permission request modal.
  function installPermission0(programName, validVersion, callback) {
    this.data.programName = programName;
    this.data.validVersion = callback;
    this.data.callback = callback;
    if (this.data.validVersion === true) {
      this.endWith({message: "We don't have permission to install " + this.data.programName + ", aborting install."});
      return;
    }
    io.sockets.emit('getPermission', { programName: this.data.programName});
    socket.on('permissionResponse', this.async(as(0)));
  },
  // If given permission, proceed. Otherwise, gracefully kill install.
  function installPermission1(permissionResponse) {
    if (permissionResponse.value !== true) {
      this.data.permissionGranted = permissionResponse.value;
      io.sockets.emit('noPermission');
      this.endWith({message: "We don't have permission to install " + this.data.programName + ", aborting install."});
      return;
    } else {
      this.data.permissionGranted = true;
      this.next();
    }

  },
  function installPermissionEnd() {
    if (this.err) {
      this.data.callback({ message: this.err.message });
      this.err = null;
    }
    this.data.callback(this.data.permissionGranted);
    this.next();
  }
);<commit_msg>Correct errors in permission bypassing code<commit_after>/**
 * @file
 * Control flow for the Kalabox installer.
 */

// Dependencies:
var flow = require('nue').flow,
    as = require('nue').as,
    parallel = require('nue').parallel,
    installUtils = require('./install-utils'),
    exec = require('child_process').exec,
    url = require('url'),
    fs = require('fs'),
    box = require('../box'),
    logger = require('../../logger'),
    taskManager = require('../utils/task-runner/task-manager'),
    config = require('../../config'),
    sudoRunner = require('../utils/task-runner/sudo-runner');

// "Constants":
var VBOX_URL = 'http://files.kalamuna.com/virtualbox-macosx-4.2.8.dmg',
    VBOX_VERSION = '4.2.8',
    TEMP_DIR = '/tmp/',
    VAGRANT_VERSION = config.get('VAGRANT_VERSION'),
    VAGRANT_URL = 'http://files.kalamuna.com/vagrant-macosx-' + VAGRANT_VERSION + '.dmg',
    VAGRANT_PLUGINS = config.get('VAGRANT_PLUGINS'),
    KALABOX_DIR = config.get('KALABOX_DIR'),
    KALABOX64_URL = 'http://files.kalamuna.com/kalabox64.box',
    KALABOX64_FILENAME = 'kalabox64.box',
    KALASTACK_DIR = config.get('KALASTACK_DIR'),
    KALASTACK_URL = config.get('KALASTACK_URL'),
    KALASTACK_FILENAME = 'kalastack.tar.gz';

// "Variables":
var socket;

// Installer file info:
var vboxUrlParsed = url.parse(VBOX_URL);
vboxUrlParsed.packageLocation = '/Volumes/VirtualBox/VirtualBox.pkg';
var vagrantUrlParsed = url.parse(VAGRANT_URL);
vagrantUrlParsed.packageLocation = '/Volumes/Vagrant/Vagrant.pkg';

// Helper functions:
function downloadAndReport(url, destination, callback) {
  // Download file via the utils.
  installUtils.downloadFile(url, destination, function(error, percentDone) {
    if (percentDone < 100) {
      // Notify client of progress.
      io.sockets.emit('installer', { complete: percentDone });
    }
    else {
      if (error) {
        installUtils.checkInternet(function(hasInternet) {
          if (!hasInternet) {
            error.message = 'No internet';
            io.sockets.emit('noInternet');
          }
          callback(error);
        });
      }
      else {
        callback(null);
      }
    }
  });
}

function sendMessage(message) {
  io.sockets.emit('installer', { message: message });
}

var installPermission = flow('installPermission')(
  // Activate the permission request modal.
  function installPermission0(programName, callback) {
    this.data.programName = programName;
    this.data.callback = callback;
    io.sockets.emit('getPermission', { programName: this.data.programName});
    socket.on('permissionResponse', this.async(as(0)));
  },
  // If given permission, proceed. Otherwise, gracefully kill install.
  function installPermission1(permissionResponse) {
    if (permissionResponse.value !== true) {
      this.data.permissionGranted = permissionResponse.value;
      io.sockets.emit('noPermission');
      this.endWith({message: "We don't have permission to install " + this.data.programName + ", aborting install."});
      return;
    } else {
      this.data.permissionGranted = true;
      this.next();
    }

  },
  function installPermissionEnd() {
    if (this.err) {
      this.data.callback({ message: this.err.message });
      this.err = null;
    }
    this.data.callback(this.data.permissionGranted);
    this.next();
  }
);
{'fraction_non_alphanumeric': 0.15232948736672997, 'fraction_numerical': 0.0058419745874105445, 'mean_word_length': 3.2613565650280023, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3933457', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2181, 'n_words': 388}