<commit_before>// This module is responsible for renaming captured video with a timestamp value

'use strict';

const fs = require('fs');
const path = require('path');
const videosDir = process.argv[2];

fs.watch(videosDir, (event, filename) => {
  if (filename.indexOf('video.h264') > -1 && filename.indexOf('~') === -1) {
    fs.rename(path.resolve(videosDir, filename), path.resolve(videosDir, `${ new Date().valueOf() }.h264`), (error) => {
      if (error) {
        process.send({
          response: 'failure',
          error,
        });
      }
    });
  }
});<commit_msg>Refactor VideoRename.js to stop throwing unnecessary errors<commit_after>// This module is responsible for renaming captured video with a timestamp value

'use strict';

const fs = require('fs');
const path = require('path');
const videosDir = process.argv[2];

const DEFAULT_FILENAME = 'video.h264';
const pathToFile = path.resolve(videosDir, DEFAULT_FILENAME);

fs.watch(videosDir, (event, filename) => {
  if (filename.indexOf(DEFAULT_FILENAME) > -1 && filename.indexOf('~') === -1) {
    fs.access(pathToFile, fs.constants.R_OK, (error) => {
      const exists = error ? false : true;

      if (exists) {
        const timestamp = new Date().valueOf();
        const pathNewFile = path.resolve(videosDir, `${ timestamp }.h264`);

        fs.rename(pathToFile, pathNewFile, (error) => {
          if (error) {
            return process.send({
              error,
            });
          }

          return process.send({
            response: 'rename',
            error: null,
          });
        });
      }
    });
  }
});
{'fraction_non_alphanumeric': 0.15636588380716934, 'fraction_numerical': 0.011124845488257108, 'mean_word_length': 2.6795454545454547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '3782004', 'n_tokens_mistral': 499, 'n_tokens_neox': 485, 'n_words': 123}