<commit_before>{File} = require 'file-utils'

class LocaleTempFileRepository

  items : null

  constructor : (@items = []) ->
    setInterval (=> @gc()), 60000

  gc : ->
    console.log 'LocaleTempFileRepository.gc'
    now = new Date()
    validUntil = now - 60
    for id, item in @items when item.created < validUntil
      console.log "LocaleTempFileRepository.gc >> Deleting #{@items[id].filePath}"
      new File(@items[id]).delete()
      @items[id] = null
    return

  add : (id) ->
    @items[id] =
      filePath : new File(id).getAbsolutePath()
      created : new Date()

  remove : (id) ->
    if @items[id]
      new File(@items[id].filePath).delete()
    return

  exist : (id) ->
    @items[id] isnt undefined

  get : (id) ->
    if @exist id
      @items[id].filePath

exports.LocaleTempFileRepository = LocaleTempFileRepository<commit_msg>Fix deleting old temp files.<commit_after>{File} = require 'file-utils'
fs = require 'fs'

class LocaleTempFileRepository

  items : null

  constructor : (@items = {}) ->
    setInterval (=> @gc()), 60000

  gc : ->
    console.log 'LocaleTempFileRepository.gc'
    now = new Date()
    validUntil = now - 60
    for id, item of @items #when item.created < validUntil
      filePath = @items[id].filePath
      console.info item.created.getTime(), validUntil
      console.log "LocaleTempFileRepository.gc >> Deleting #{filePath}..."
      @remove id
    return

  add : (id) ->
    @items[id] =
      filePath : new File('../' + id).getAbsolutePath()
      created : new Date()

  remove : (id) ->
    if @items[id]
      fs.unlink @items[id].filePath, => delete @items[id]
    return

  exist : (id) ->
    @items[id] isnt undefined

  get : (id) ->
    if @exist id
      @items[id].filePath

exports.LocaleTempFileRepository = LocaleTempFileRepository
{'fraction_non_alphanumeric': 0.14199229499174462, 'fraction_numerical': 0.007705008255365988, 'mean_word_length': 2.819327731092437, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '5368103', 'n_tokens_mistral': 604, 'n_tokens_neox': 575, 'n_words': 146}