<commit_before>Promise = require 'bluebird'
path = require 'path'
fs = require 'fs-extra'
{log, warn, error} = require './utils'

{ROOT, EXROOT} = global

config = {}
defaultConfigPath = path.join(ROOT, 'config.json')
configPath = path.join(EXROOT, 'config.json')

# Read saved config
try
  fs.accessSync defaultConfigPath, fs.R_OK | fs.W_OK
  config = fs.readJsonSync defaultConfigPath
catch e
  warn e

# Read user config
try
  fs.accessSync configPath, fs.R_OK | fs.W_OK
  config = fs.readJsonSync configPath
catch e
  warn e

module.exports =
  get: (path, value) ->
    path = path.split('.').filter (p) -> p != ''
    cur = config
    for p in path
      cur = cur?[p]
    if cur? then cur else value
  set: (path, value) ->
    path = path.split('.').filter (p) -> p != ''
    cur = config
    len = path.length
    for p, i in path
      if i != len - 1
        cur[p] = {} if typeof cur[p] != 'object'
        cur = cur[p]
      else
        cur[p] = value
    # Save to file
    try
      fs.accessSync configPath, fs.R_OK | fs.W_OK
      fs.writeJsonSync configPath, config
    catch e
      warn e
<commit_msg>Fix access<commit_after>Promise = require 'bluebird'
path = require 'path'
fs = require 'fs-extra'
{log, warn, error} = require './utils'

{ROOT, EXROOT} = global

config = {}
defaultConfigPath = path.join(ROOT, 'config.json')
configPath = path.join(EXROOT, 'config.json')

# Read saved config
try
  fs.accessSync defaultConfigPath, fs.R_OK | fs.W_OK
  config = fs.readJsonSync defaultConfigPath
catch e
  warn e

# Read user config
try
  fs.accessSync configPath, fs.R_OK | fs.W_OK
  config = fs.readJsonSync configPath
catch e
  warn e

module.exports =
  get: (path, value) ->
    path = path.split('.').filter (p) -> p != ''
    cur = config
    for p in path
      cur = cur?[p]
    if cur? then cur else value
  set: (path, value) ->
    path = path.split('.').filter (p) -> p != ''
    cur = config
    len = path.length
    for p, i in path
      if i != len - 1
        cur[p] = {} if typeof cur[p] != 'object'
        cur = cur[p]
      else
        cur[p] = value
    # Save to file
    try
      fs.writeFileSync configPath, JSON.stringify(config, null, 2)
    catch e
      warn e

{'fraction_non_alphanumeric': 0.13086642599277978, 'fraction_numerical': 0.0013537906137184115, 'mean_word_length': 2.5472, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2710111', 'n_tokens_mistral': 774, 'n_tokens_neox': 770, 'n_words': 241}