<commit_before>#!/usr/bin/env node

var fs = require('fs');
var _  = require('underscore');

var last_change = 0;
var changes     = {};
var dirs        = [];
var watched     = [];
var wait_msg_shown = false;

var ons = [ ];

var exec = require('child_process').exec;
var spawn = require('child_process').spawn;

function inform(msg) {
  console['log']("==== " + msg);
}

function warn(msg) {
  console['log']("warning: ==== " + msg);
}

function is_running() { return river.ops.length > 0; }

var river = {
  ops: [],
  push: function (func) {
    river.ops.push(func);
  },
  start: function () {
    river.next();
  },
  next: function () {
    if (!river.ops.length)
      return;
    river.ops.shift()();
  },
  fin: function () {
    river.next();
  },
  err: function (msg) {
    river.ops = [];
  }
};


function watch(str_or_list, func) {
  dirs.push(str_or_list);
  dirs = _.uniq(_.flatten(dirs));
  ons.push([str_or_list, func]);
  _.each(dirs, function (name) {
    if (_.contains(watched, name))
      return false;
    fs.watch(name, function (event, file_name) { files_changed(name, file_name); });
    watched.push(name);
    exec("find " + name + " -type d ", function (err, o, e) {
      if (err) {
        warn(err.message);
        return;
      }

      if (e)
        warn(e)

      watch((o + '').trim().split("\n"), func);
    });
  });
}

function files_changed(dir, file_name) {
  if (is_running()) {
    if (dir || file_name) {
      if (!wait_msg_shown) {
        inform("Still waiting for other funcs to finish.");
        wait_msg_shown = true;
      }
    }
    return;
  }

  if (dir || file_name) {
    changes[dir] = file_name;
    last_change = (new Date).getTime();
    return files_changed();
  }
<commit_msg>Fixed: sub-folder listed was including parent.<commit_after>#!/usr/bin/env node

var fs = require('fs');
var _  = require('underscore');

var last_change = 0;
var changes     = {};
var dirs        = [];
var watched     = [];
var wait_msg_shown = false;

var ons = [ ];

var exec = require('child_process').exec;
var spawn = require('child_process').spawn;

function inform(msg) {
  console['log']("==== " + msg);
}

function warn(msg) {
  console['log']("warning: ==== " + msg);
}

function is_running() { return river.ops.length > 0; }

var river = {
  ops: [],
  push: function (func) {
    river.ops.push(func);
  },
  start: function () {
    river.next();
  },
  next: function () {
    if (!river.ops.length)
      return;
    river.ops.shift()();
  },
  fin: function () {
    river.next();
  },
  err: function (msg) {
    river.ops = [];
  }
};


function watch(str_or_list, func) {
  dirs.push(str_or_list);
  dirs = _.uniq(_.flatten(dirs));
  ons.push([str_or_list, func]);
  _.each(dirs, function (name) {
    if (_.contains(watched, name))
      return false;
    fs.watch(name, function (event, file_name) { files_changed(name, file_name); });
    watched.push(name);
    exec("find " + name + " -mindepth 1 -type d ", function (err, o, e) {
      if (err) {
        warn(err.message);
        return;
      }

      if (e)
        warn(e)

      o = (o + '').trim();
      if (!o.length)
        return;
      watch(o.split("\n"), func);
    });
  });
}

function files_changed(dir, file_name) {
  if (is_running()) {
    if (dir || file_name) {
      if (!wait_msg_shown) {
        inform("Still waiting for other funcs to finish.");
        wait_msg_shown = true;
      }
    }
    return;
  }

  if (dir || file_name) {
    changes[dir] = file_name;
    last_change = (new Date).getTime();
    return files_changed();
  }

{'fraction_non_alphanumeric': 0.18326359832635983, 'fraction_numerical': 0.001394700139470014, 'mean_word_length': 2.644308943089431, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3660533', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1280, 'n_words': 280}