<commit_before>var _ = require('underscore'),
    fs = require('fs'),
    mkdirp = require('mkdirp'),
    path = require('path'),
    folders = require('./folders');

function Overrides() {
    this.save = {
        folders: function(proxy, route) {
            if (proxy.override && route.overrides) {
                if (Array.isArray(proxy.override) && proxy.override.length > 0) {
                    _.each(proxy.override, function(key, index) {
                        var override = route.overrides[key];
                        var name = override.name || override.folder || index || 'override';
                        override.name = path.join(proxy.name, name);
                        folders[override.name] = folders[proxy.name];
                        if (override && override.folder) {
                            folders[override.name] = path.join(folders[route.name], override.folder);
                            if (!fs.existsSync(folders[override.name])) {
                                mkdirp.sync(folders[override.name]);
                            }
                            return;
                        }
                    }, this);
                } else {
                    var override = route.overrides[proxy.override];
                    var name = override.name || override.folder.join(',') || 'override';
                    if (!override.name) {
                        override.name = path.join(proxy.name, name);
                    }
                    if (!folders[override.name]) {
                        folders[override.name] = folders[proxy.name];
                        if (override && override.folder) {
                            if (Array.isArray(override.folder)) {
                                folders[override.name] = [];
                                folders[override.name].name = override.name;
                                folders[override.name].index = 0;
                                folders[override.name].time = new Date().getTime();
                                folders[override.name].next = function() {
                                    ++this.index;
                                    if (this.index >= this.length) {
                                        this.index = 0;
                                    }
                                }.bind(folders[override.name]);
                                if (override.type === 'time' && override.delay > 0) {
                                    folders[override.name].next = function() {
                                        if (new Date().getTime() - this.time > override.delay) {
                                            this.time = new Date().getTime();
                                            ++this.index;
                                            if (this.index >= this.length) {
                                                this.index = 0;
                                            }
                                        }
                                    }.bind(folders[override.name]);
                                }
                                folders[override.name].current = function() {
                                    return this[this.index];
                                }.bind(folders[override.name]);
                                _.each(override.folder, function(folder) {
                                    var oFolder = path.join(folders[route.name], folder);
                                    folders[override.name].push(oFolder);
                                    if (!fs.existsSync(oFolder)) {
                                        mkdirp.sync(oFolder);
                                    }
                                }, this);
                            } else {
                                folders[override.name] = path.join(folders[route.name], override.folder);
                                if (!fs.existsSync(folders[override.name])) {
                                    mkdirp.sync(folders[override.name]);
                                }
                            }<commit_msg>Fix crash with POST data when override.folder is not an array<commit_after>var _ = require('underscore'),
    fs = require('fs'),
    mkdirp = require('mkdirp'),
    path = require('path'),
    folders = require('./folders');

function joinIfArray(folder) {
    if (Array.isArray(folder)) {
        return folder.join(',');
    }
    return folder;
}

function Overrides() {
    this.save = {
        folders: function(proxy, route) {
            if (proxy.override && route.overrides) {
                if (Array.isArray(proxy.override) && proxy.override.length > 0) {
                    _.each(proxy.override, function(key, index) {
                        var override = route.overrides[key];
                        var name = override.name || override.folder || index || 'override';
                        override.name = path.join(proxy.name, name);
                        folders[override.name] = folders[proxy.name];
                        if (override && override.folder) {
                            folders[override.name] = path.join(folders[route.name], override.folder);
                            if (!fs.existsSync(folders[override.name])) {
                                mkdirp.sync(folders[override.name]);
                            }
                            return;
                        }
                    }, this);
                } else {
                    var override = route.overrides[proxy.override];
                    if (override) {
                        var name = override.name || joinIfArray(override.folder) || 'override';
                        if (!override.name) {
                            override.name = path.join(proxy.name, name);
                        }
                        if (!folders[override.name]) {
                            folders[override.name] = folders[proxy.name];
                            if (override.folder) {
                                if (Array.isArray(override.folder)) {
                                    folders[override.name] = [];
                                    folders[override.name].name = override.name;
                                    folders[override.name].index = 0;
                                    folders[override.name].time = new Date().getTime();
                                    folders[override.name].next = function() {
                                        ++this.index;
                                        if (this.index >= this.length) {
                                            this.index = 0;
                                        }
                                    }.bind(folders[override.name]);
                                    if (override.type === 'time' && override.delay > 0) {
                                        folders[override.name].next = function() {
                                            if (new Date().getTime() - this.time > override.delay) {
                                                this.time = new Date().getTime();
                                                ++this.index;
                                                if (this.index >= this.length) {
                                                    this.index = 0;
                                                }
                                            }
                                        }.bind(folders[override.name]);
                                    }
                                    folders[override.name].current = function() {
                                        return this[this.index];
                                    }.bind(folders[override.name]);
                                    _.each(override.folder, function(folder) {
                                        var oFolder = path.join(folders[route.name], folder);
                                        folders[override.name].push(oFolder);
                                        if (!fs.existsSync(oFolder)) {
                                            mkdirp.sync(oFolder);
                                        }
                                    }, this);
                                } else {
                                    folders[override.name] = path.join(folders[route.name], override.folder);
                                    if (!fs.existsSync(folders[override.name])) {
                                        mkdirp.sync(folders[override.name]);
                                    }
                                }
                            }
{'fraction_non_alphanumeric': 0.10291396854764108, 'fraction_numerical': 0.001156336725254394, 'mean_word_length': 0.8239139603542809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 78, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '183911', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1712, 'n_words': 291}