<commit_before>// More responsible file watching.

var fs = require('fs');
var events = require('events');

exports.__fs = fs;

var OPTIONS = { persistent: true, interval: 100 };
var emitter = new events.EventEmitter();
emitter.setMaxListeners(100);

exports.listeners = function(file) {
  return emitter.listeners(file);
};

exports.watch = function(file, callback) {
  var listeners = emitter.listeners(file);
  if (listeners.length) {
    callback.watcher = listeners[0].watcher;
  } else {
    try {
      var fn = function(event, filename) {
        if (event == 'rename') {
          emitter.emit(file);
        }
      };
      callback.watcher = exports.__fs.watch(file, OPTIONS, fn);
      emitter.on(file, callback);
    } catch(e) {
      return null;
    }
  }
  return callback;
};

exports.unwatch = function(file, callback) {
  var listener = emitter.listeners(file)[0];
  emitter.removeListener(file, callback);
  if (!emitter.listeners(file).length && listener) {
    listener.watcher.close();
  }
};<commit_msg>Linux fix for file watching.<commit_after>// More responsible file watching.

var fs = require('fs');
var events = require('events');

exports.__fs = fs;

var OPTIONS = { persistent: true, interval: 100 };
var emitter = new events.EventEmitter();
emitter.setMaxListeners(100);

exports.listeners = function(file) {
  return emitter.listeners(file);
};

exports.watch = function(file, callback) {
  var listeners = emitter.listeners(file);
  if (listeners.length) {
    callback.watcher = listeners[0].watcher;
  } else {
    try {
      var fileTimer = null;
      var fn = function(event, filename) {
        if (fileTimer) {
          return;
        }
        fileTimer = setTimeout(function() { fileTimer = null; }, 200);
        emitter.emit(file);
      };
      callback.watcher = exports.__fs.watch(file, OPTIONS, fn);
      emitter.on(file, callback);
    } catch(e) {
      return null;
    }
  }
  return callback;
};

exports.unwatch = function(file, callback) {
  var listener = emitter.listeners(file)[0];
  emitter.removeListener(file, callback);
  if (!emitter.listeners(file).length && listener) {
    listener.watcher.close();
  }
};
{'fraction_non_alphanumeric': 0.14357798165137614, 'fraction_numerical': 0.00871559633027523, 'mean_word_length': 3.293307086614173, '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': '2587729', 'n_tokens_mistral': 701, 'n_tokens_neox': 670, 'n_words': 154}