<commit_before>
@ledger ?= {}
@ledger.utils ?= {}

class @ledger.utils.Log

  ###
    Constructor
    @param [Number] _daysMax The maximum number of days the logs are preserved
  ###
  constructor: (daysMax = 2) ->
    @_daysMax = daysMax
    @_daysMax = parseInt(@_daysMax)
    unlockWriter = _.lock @, ['constructor', '_getFileWriter', 'write', 'read']
    if isNaN @_daysMax
      throw 'The first parameter must be a number'
    _init = (fs) =>
      @_fs = fs
      @_setFileName()
      # Delete old log files
      @listDirFiles (files) =>
        unless _(files).isEmpty()
          for file in files
            filedate = file.name.substr(-14, 10)
            ms = moment(moment().format('YYYY-MM-DD')).diff moment(_.str.dasherize(filedate))
            days   = moment.duration(ms).days()
            months = moment.duration(ms).months()
            years = moment.duration(ms).years()
            # l 'days: ', days, 'months: ', months, 'years: ', years
            if days > @_daysMax or months > 0 or years > 0
              @delete file.name
            # l 'days: ', days, 'months: ', months, 'years: ', years
        unlockWriter()
    window.webkitRequestFileSystem window.PERSISTENT, 5*1024*1024, _init, @_errorHandler



  ###
    Delete a file
    @param [String] filename The name of the file
  ###<commit_msg>remove constructor from lock fn<commit_after>
@ledger ?= {}
@ledger.utils ?= {}

class @ledger.utils.Log

  ###
    Constructor
    @param [Number] _daysMax The maximum number of days the logs are preserved
  ###
  constructor: (daysMax = 2) ->
    @_daysMax = daysMax
    @_daysMax = parseInt(@_daysMax)
    unlockWriter = _.lock @, ['_getFileWriter', 'write', 'read']
    if isNaN @_daysMax
      throw 'The first parameter must be a number'
    _init = (fs) =>
      @_fs = fs
      @_setFileName()
      # Delete old log files
      @listDirFiles (files) =>
        unless _(files).isEmpty()
          for file in files
            filedate = file.name.substr(-14, 10)
            ms = moment(moment().format('YYYY-MM-DD')).diff moment(_.str.dasherize(filedate))
            days   = moment.duration(ms).days()
            months = moment.duration(ms).months()
            years = moment.duration(ms).years()
            # l 'days: ', days, 'months: ', months, 'years: ', years
            if days > @_daysMax or months > 0 or years > 0
              @delete file.name
            # l 'days: ', days, 'months: ', months, 'years: ', years
        unlockWriter()
    window.webkitRequestFileSystem window.PERSISTENT, 5*1024*1024, _init, @_errorHandler



  ###
    Delete a file
    @param [String] filename The name of the file
  ###
{'fraction_non_alphanumeric': 0.13525665043087298, 'fraction_numerical': 0.011989509179467965, 'mean_word_length': 2.371212121212121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '221400', 'n_tokens_mistral': 851, 'n_tokens_neox': 804, 'n_words': 229}