<commit_before>var fs = require('fs')
  , zlib = require('zlib')
  , path = require('path');

module.exports = function(file, options, cb) {
  if(typeof cb === 'undefined') {
    cb = options;
    options = {}
  }

  var dir   = path.dirname(file)
    , name  = path.basename(file)
    , count = options.count ? (options.count - 1) : null
    // regex for matching rotations of the current log
    , reg   = (options.matcher || new RegExp(name + "\\.\\d+\\.?"))

  fs.readdir(dir, function(err, files) {
    if(err) return cb(err);
    var toShift = []
      , i, l;

    // get matching files from dir
    for(i = 0, l = files.length; i < l; i++) {
      if(reg.test(files[i]) === true) { toShift.push(files[i]) }
    }

    // reverse sort files by name
    toShift.sort(function(a, b) { return b > a ? 1 : -1; });

    // increment each files index
    for(i = 0, l = toShift.length; i < l; i++) {
      // remove log files outside of the `count` limit
      if(typeof count !== "undefined" && l >= count && i <= (l - count)) {
        fs.unlinkSync(path.join(dir, '/', toShift[i]));
      } else {
        var parts = toShift[i].split('.');
        // increment the log file index
        for(var j = parts.length; j >= 0; j--) {
          if( isNaN(parts[j]) === false ) {
            parts[j] = +parts[j] + 1; break;
          }
        }
        // move the file to the new index
        fs.renameSync(<commit_msg>fix file count null check<commit_after>var fs = require('fs')
  , zlib = require('zlib')
  , path = require('path');

module.exports = function(file, options, cb) {
  if(typeof cb === 'undefined') {
    cb = options;
    options = {}
  }

  var dir   = path.dirname(file)
    , name  = path.basename(file)
    , count = options.count ? (options.count - 1) : null
    // regex for matching rotations of the current log
    , reg   = (options.matcher || new RegExp(name + "\\.\\d+\\.?"))

  fs.readdir(dir, function(err, files) {
    if(err) return cb(err);
    var toShift = []
      , i, l;

    // get matching files from dir
    for(i = 0, l = files.length; i < l; i++) {
      if(reg.test(files[i]) === true) { toShift.push(files[i]) }
    }

    // reverse sort files by name
    toShift.sort(function(a, b) { return b > a ? 1 : -1; });

    // increment each files index
    for(i = 0, l = toShift.length; i < l; i++) {
      // remove log files outside of the `count` limit
      if(count !== null && l >= count && i <= (l - count)) {
        fs.unlinkSync(path.join(dir, '/', toShift[i]));
      } else {
        var parts = toShift[i].split('.');
        // increment the log file index
        for(var j = parts.length; j >= 0; j--) {
          if( isNaN(parts[j]) === false ) {
            parts[j] = +parts[j] + 1; break;
          }
        }
        // move the file to the new index
        fs.renameSync(
{'fraction_non_alphanumeric': 0.176056338028169, 'fraction_numerical': 0.004929577464788733, 'mean_word_length': 2.101528384279476, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3324974', 'n_tokens_mistral': 974, 'n_tokens_neox': 950, 'n_words': 274}