<commit_before>var Fs = require('fire-fs');
var Path = require('fire-path');
var PathWatcher = require('pathwatcher');
var Gulp = require('gulp');
var EventStream = require ('event-stream');
var Util = require ('util');
var Events = require ('events');

var commandPriority = { delete: 0, new: 1, change: 2 };
var globalDiff = process.platform === 'win32';

function _dbgPrintResults ( results ) {
    for ( var p in results ) {
        console.log( "%s: %s", results[p].command, results[p].path );
    }
}

function _addResult ( results, command, path, isDirectory ) {
    var result = results[path];
    if ( result ) {
        if ( result.isDirectory !== isDirectory ) {
            throw new Error("We not support file and directory share the same path " + path );
        }

        if ( commandPriority[result.command] > commandPriority[command] ) {
            result.command = command;
        }

        return;
    }

    results[path] = {
        command: command,
        path: path,
        isDirectory: isDirectory
    };
}

function _watch ( fireWatcher ) {
    if ( globalDiff ) {
        return EventStream.through(function (file) {
            fireWatcher.files[file.path] = { file: file, children: [] };

            var parent = fireWatcher.files[Path.dirname(file.path)];
            parent.children.push( file.path );

            if ( file.stat.isDirectory() ) {
                fireWatcher.changes[file.path] = { command: "change", path: file.path };
            }

            this.push(file);
        });
    }

    return EventStream.through(function (file) {
        fireWatcher.files[file.path] = { file: file, children: [] };

        var parent = fireWatcher.files[Path.dirname(file.path)];
        parent.children.push( file.path );

        var pathWatcher = PathWatcher.watch( file.path, function ( event, path ) {
            // console.log("DEBUG: %s, %s, %s", event, file.path, path);

            if ( event === "delete" ) {
                pathWatcher.close();
            }
            fireWatcher.changes[file.path] = { command: event, path: file.path, relatedPath: path };
            // TODO: _cooldown(fireWatcher);
        } );

        this.push(file);<commit_msg>add protection for undefined error<commit_after>var Fs = require('fire-fs');
var Path = require('fire-path');
var PathWatcher = require('pathwatcher');
var Gulp = require('gulp');
var EventStream = require ('event-stream');
var Util = require ('util');
var Events = require ('events');

var commandPriority = { delete: 0, new: 1, change: 2 };
var globalDiff = process.platform === 'win32';

function _dbgPrintResults ( results ) {
    for ( var p in results ) {
        console.log( "%s: %s", results[p].command, results[p].path );
    }
}

function _addResult ( results, command, path, isDirectory ) {
    var result = results[path];
    if ( result ) {
        if ( result.isDirectory !== isDirectory ) {
            throw new Error("We not support file and directory share the same path " + path );
        }

        if ( commandPriority[result.command] > commandPriority[command] ) {
            result.command = command;
        }

        return;
    }

    results[path] = {
        command: command,
        path: path,
        isDirectory: isDirectory
    };
}

function _watch ( fireWatcher ) {
    if ( globalDiff ) {
        return EventStream.through(function (file) {
            fireWatcher.files[file.path] = { file: file, children: [] };

            var parent = fireWatcher.files[Path.dirname(file.path)];
            parent.children.push( file.path );

            if ( file.stat.isDirectory() ) {
                fireWatcher.changes[file.path] = { command: "change", path: file.path };
            }

            this.push(file);
        });
    }

    return EventStream.through(function (file) {
        fireWatcher.files[file.path] = { file: file, children: [] };

        var parent = fireWatcher.files[Path.dirname(file.path)];
        if ( !parent ) {
            console.error('Watch failed: Can not find path: %s', Path.dirname(file.path) );
            return;
        }

        parent.children.push( file.path );

        var pathWatcher = PathWatcher.watch( file.path, function ( event, path ) {
            // console.log("DEBUG: %s, %s, %s", event, file.path, path);

            if ( event === "delete" ) {
                pathWatcher.close();
            }
            fireWatcher.changes[file.path] = { command: event, path: file.path, relatedPath: path };
            // TODO: _cooldown(fireWatcher);
        } );

        this.push(file);
{'fraction_non_alphanumeric': 0.14077140989322293, 'fraction_numerical': 0.0021791239921551534, 'mean_word_length': 2.2622601279317696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6548985', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1305, 'n_words': 322}