<commit_before>var exec = require("child_process").exec
var fs = require("fs")
var http = require("http")
var path = require("path")
var shasum = require("crypto").createHash("sha1")
var mkdirp = require("mkdirp")
var url = require("../config").url
var dirname = require("../config").dirname

module.exports = function (version) {
  var body = ""
  if (version.substring(0, 1) !== "v") version = "v" + version
  var exists = fs.existsSync(path.join(dirname.src, version))
  if (exists) {
    console.log(version +" is already installed.\n")
  }
  version = version.substr(1)

  http.get(url, function(res) {
    if(res.statusCode !== 200) {
      var message = "Error: Server responsed status code "
      message += res.statusCode
      console.error(message)
    }
    res.on("data", function(chunk) { body += chunk })

    res.on("end", function() {
      body = JSON.parse(body)
      var versions = Object.keys(body.versions)
      if (versions.indexOf(version) === -1) {
        console.log("Unknown version: " + version)
        return
      }
      var dist = body.versions[version].dist
      var buffer = []
      var buffersize = 0
      http.get(dist.tarball, function (res) {
        res.on("data", function (chunk) {
          buffer.push(chunk)
          buffersize += chunk.length
        })
        res.on("end", function() {
          var data = Buffer.concat(buffer, buffersize)
          shasum.update(data)
          if(shasum.digest("hex") !== dist.shasum) {
            console.error("Error: Download data is broken")
            return
          }
          var exists = fs.existsSync(dirname.src)
          if(!exists) mkdirp.sync(dirname.src)
          var file_name = dirname.src + "/npm-" + version + "/npm-"
          file_name += version + ".tgz"
          mkdirp.sync(dirname.src + "/npm-" + version)
          fs.openSync(file_name, "w+")
          var writeStream = fs.createWriteStream(file_name)
          writeStream.on("error", function (e) {
            console.error(e.message)
          })
          writeStream.write(data, "binary")
          writeStream.end()
          writeStream.on("close", function () {
            var command = "tar -zxf " + file_name
            command += " -C " + dirname.src + "/npm-" + version
            exec.exec(command, {encoding : "utf8"}, function () {
              var oldPath = dirname.src + "/npm-" + version + "/package"
              var newPath = dirname.npm + "/v" + version
              var exists = fs.existsSync(dirname.npm)
              if(!exists) mkdirp.sync(dirname.npm)
              exists = fs.existsSync(newPath)
              if (!exists) fs.renameSync(oldPath, newPath)
              var pkg = require(path.join(newPath, "package.json"))
              var bin = typeof pkg.bin === "string" ?
                pkg.bin : typeof pkg.bin === "object" ?
                pkg.bin.npm : false
              if (!bin) {
                console.log("There isn't bin prop in package.json for npmbrew")
                return
              }
              bin = path.join(dirname.current, pkg.bin)
              exec(
                "cd " + newPath + " " + bin + " install",
                {encoding : "utf8"},
                function (error) {
                  if (error) {
                    console.log(error)
                  } else {
                    console.log("installed")
                  }
                }
              )
            })
          })
        })
      }).on("error", function(e) {
        console.error(e.message)
      })
    })
  }).on("error", function(e) {
    console.error(e.message)
  })
}
<commit_msg>Fixes exec bug<commit_after>var exec = require("child_process").exec
var fs = require("fs")
var http = require("http")
var path = require("path")
var shasum = require("crypto").createHash("sha1")
var mkdirp = require("mkdirp")
var url = require("../config").url
var dirname = require("../config").dirname

module.exports = function (version) {
  var body = ""
  if (version.substring(0, 1) !== "v") version = "v" + version
  var exists = fs.existsSync(path.join(dirname.src, version))
  if (exists) {
    console.log(version +" is already installed.\n")
  }
  version = version.substr(1)

  http.get(url, function(res) {
    if(res.statusCode !== 200) {
      var message = "Error: Server responsed status code "
      message += res.statusCode
      console.error(message)
    }
    res.on("data", function(chunk) { body += chunk })

    res.on("end", function() {
      body = JSON.parse(body)
      var versions = Object.keys(body.versions)
      if (versions.indexOf(version) === -1) {
        console.log("Unknown version: " + version)
        return
      }
      var dist = body.versions[version].dist
      var buffer = []
      var buffersize = 0
      http.get(dist.tarball, function (res) {
        res.on("data", function (chunk) {
          buffer.push(chunk)
          buffersize += chunk.length
        })
        res.on("end", function() {
          var data = Buffer.concat(buffer, buffersize)
          shasum.update(data)
          if(shasum.digest("hex") !== dist.shasum) {
            console.error("Error: Download data is broken")
            return
          }
          var exists = fs.existsSync(dirname.src)
          if(!exists) mkdirp.sync(dirname.src)
          var file_name = dirname.src + "/npm-" + version + "/npm-"
          file_name += version + ".tgz"
          mkdirp.sync(dirname.src + "/npm-" + version)
          fs.openSync(file_name, "w+")
          var writeStream = fs.createWriteStream(file_name)
          writeStream.on("error", function (e) {
            console.error(e.message)
          })
          writeStream.write(data, "binary")
          writeStream.end()
          writeStream.on("close", function () {
            var command = "tar -zxf " + file_name
            command += " -C " + dirname.src + "/npm-" + version
            exec(command, {encoding : "utf8"}, function () {
              var oldPath = dirname.src + "/npm-" + version + "/package"
              var newPath = dirname.npm + "/v" + version
              var exists = fs.existsSync(dirname.npm)
              if(!exists) mkdirp.sync(dirname.npm)
              exists = fs.existsSync(newPath)
              if (!exists) fs.renameSync(oldPath, newPath)
              var pkg = require(path.join(newPath, "package.json"))
              var bin = typeof pkg.bin === "string" ?
                pkg.bin : typeof pkg.bin === "object" ?
                pkg.bin.npm : false
              if (!bin) {
                console.log("There isn't bin prop in package.json for npmbrew")
                return
              }
              bin = path.join(dirname.current, pkg.bin)
              exec(
                "cd " + newPath + " " + bin + " install",
                {encoding : "utf8"},
                function (error) {
                  if (error) {
                    console.log(error)
                  } else {
                    console.log("installed")
                  }
                }
              )
            })
          })
        })
      }).on("error", function(e) {
        console.error(e.message)
      })
    })
  }).on("error", function(e) {
    console.error(e.message)
  })
}

{'fraction_non_alphanumeric': 0.14445056458275957, 'fraction_numerical': 0.003029468465987331, 'mean_word_length': 1.759498480243161, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1166999', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2075, 'n_words': 458}