<commit_before>
var fs   = require('fs')
var sum  = require('sha1sum')
var join = require('path').join

module.exports = function (name) {

  if(!name)
    throw new Error('provide app name')

  var id_file = join(process.env.HOME, '.udid-' + name)
  var UDID

  ;(function () {

    try {
      return UDID = 
        sum(fs.readFileSync(join(process.env.HOME, '.ssh', 'id_rsa.pub')) + name)
    } catch (_) {}

    try {
      return UDID = 
        fs.readFileSync(id_file)
    } catch (_) {}

    module.exports = sum(Date.now())

  })()

  fs.writeFileSync(id_file, UDID)

  return UDID

}
if(!module.parent)
  console.log(module.exports(process.argv[2]))

<commit_msg>avoid possible race condition<commit_after>
var fs   = require('fs')
var sum  = require('sha1sum')
var join = require('path').join

var IDS = {}

module.exports = function (name) {


  if(!name)
    throw new Error('provide app name')

  //this should never happen, but just to be sure...
  if(IDS[name]) return IDS[name]

  var id_file = join(process.env.HOME, '.udid-' + name)

  var UDID = (function () {

    try {
      return sum(fs.readFileSync(join(process.env.HOME, '.ssh', 'id_rsa.pub')) + name)
    } catch (_) {}

    try {
      return fs.readFileSync(id_file)
    } catch (_) {}

    return sum(Date.now())

  })()

  IDS[name] = UDID.toString()
  fs.writeFileSync(id_file, UDID)

  return UDID.toString()

}
if(!module.parent)
  console.log(module.exports(process.argv[2]))


{'fraction_non_alphanumeric': 0.16530054644808742, 'fraction_numerical': 0.00273224043715847, 'mean_word_length': 3.0247252747252746, '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': '2901487', 'n_tokens_mistral': 558, 'n_tokens_neox': 526, 'n_words': 113}