<commit_before>
// like rm -rf

module.exports = rm

var fs = require("./graceful-fs")
  , path = require("path")
  , sys = require("./sys")
  , failedToRemove = []
  , log = require("./log")
  , exec = require("./exec")
  , constants = require("constants")

process.on("exit", function () {
  if (failedToRemove.length === 0) return
  sys.error("")
  log("The following files and folders could not be removed", "!")
  log("You should remove them manually.", "!")
  sys.error( "\nsudo rm -rf "
           + failedToRemove.map(JSON.stringify).join(" ") )
  failedToRemove.length = 0
})

var waitBusy = {}
  , maxTries = 3
function rm (p, cb_) {

  if (!p) return cb_(new Error("Trying to rm nothing?"))

  function cb (er) {
    if (er) {
      if (er.message.match(/^EBUSY/)) {
        // give it 3 tries
        // windows takes a while to actually remove files from folders,
        // leading to this odd EBUSY error when you try to rm a directory,
        // even if it's actually been emptied.
        if (!waitBusy.hasOwnProperty(p)) waitBusy[p] = maxTries
        if (waitBusy[p]) {
          waitBusy[p] --
          // give it 100 ms more each time.
          var time = (maxTries - waitBusy[p]) * 100
          return setTimeout(function () { rm(p, cb_) }, time)
        }
      }
      if (er.errno === constants.EACCES) {
        // ask for privs
        var sudoEnv ={SUDO_PROMPT:"[npm rm "+p+"] Password:"
                     ,SUDO_UID:process.getuid()}
        for (var i in process.env) sudoEnv[i] = process.env[i]
        log.warn("Upgrade permissions to remove "+p, "rm")
        return exec("sudo", ["rm", "-r", p]
                   ,sudoEnv
                   ,true
                   ,cb)
      }
      failedToRemove.push(p)
      log(p, "rm fail")
      log(er.message, "rm fail")
    } else delete waitBusy[p]
    cb_(null, er)
  }

  fs.lstat(p, function (er, s) {
    if (er) return cb()
    if (s.isFile() || s.isSymbolicLink()) {
      fs.unlink(p, cb)
    } else {
      fs.readdir(p, function (er, files) {
        if (er) return cb(er)
        ;(function rmFile (f) {
          if (!f) fs.rmdir(p, cb)
          else rm(path.join(p, f), function (_, er) {
            if (er) return cb(er)
            rmFile(files.pop())
          })
        })(files.pop())
      })
    }
  })
}
<commit_msg>Cooler prompt<commit_after>
// like rm -rf

module.exports = rm

var fs = require("./graceful-fs")
  , path = require("path")
  , sys = require("./sys")
  , failedToRemove = []
  , log = require("./log")
  , exec = require("./exec")
  , constants = require("constants")

process.on("exit", function () {
  if (failedToRemove.length === 0) return
  sys.error("")
  log("The following files and folders could not be removed", "!")
  log("You should remove them manually.", "!")
  sys.error( "\nsudo rm -rf "
           + failedToRemove.map(JSON.stringify).join(" ") )
  failedToRemove.length = 0
})

var waitBusy = {}
  , maxTries = 3
function rm (p, cb_) {

  if (!p) return cb_(new Error("Trying to rm nothing?"))

  function cb (er) {
    if (er) {
      if (er.message.match(/^EBUSY/)) {
        // give it 3 tries
        // windows takes a while to actually remove files from folders,
        // leading to this odd EBUSY error when you try to rm a directory,
        // even if it's actually been emptied.
        if (!waitBusy.hasOwnProperty(p)) waitBusy[p] = maxTries
        if (waitBusy[p]) {
          waitBusy[p] --
          // give it 100 ms more each time.
          var time = (maxTries - waitBusy[p]) * 100
          return setTimeout(function () { rm(p, cb_) }, time)
        }
      }
      if (er.errno === constants.EACCES) {
        // ask for privs
        var sudoEnv ={SUDO_PROMPT:"[npm rm "+p+"] Password:"}
        for (var i in process.env) sudoEnv[i] = process.env[i]
        log.warn("rm "+p, "privilege escalation")
        return exec("sudo", ["rm", "-r", p]
                   ,sudoEnv
                   ,true
                   ,cb)
      }
      failedToRemove.push(p)
      log(p, "rm fail")
      log(er.message, "rm fail")
    } else delete waitBusy[p]
    cb_(null, er)
  }

  fs.lstat(p, function (er, s) {
    if (er) return cb()
    if (s.isFile() || s.isSymbolicLink()) {
      fs.unlink(p, cb)
    } else {
      fs.readdir(p, function (er, files) {
        if (er) return cb(er)
        ;(function rmFile (f) {
          if (!f) fs.rmdir(p, cb)
          else rm(path.join(p, f), function (_, er) {
            if (er) return cb(er)
            rmFile(files.pop())
          })
        })(files.pop())
      })
    }
  })
}

{'fraction_non_alphanumeric': 0.15995647442872687, 'fraction_numerical': 0.004352557127312296, 'mean_word_length': 1.974757281553398, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3664773', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1535, 'n_words': 426}