<commit_before>"use strict";

var spawn = require("child_process").spawn;
var util = require("util");
var _ = require("lodash");

exports.rsync = function (options,callback) {

    options = options || {};

    if ( typeof options.src === "undefined" ) {
        throw(new Error("'src' directory is missing from options"));
    }

    if ( typeof options.dest === "undefined" ) {
        throw(new Error("'dest' directory is missing from options"));
    }

    if ( typeof options.host !== "undefined" ) {
        options.dest = options.host+":"+options.dest;
    }

    var args = [options.src,options.dest];

    if ( typeof options.host !== "undefined" ) {
        args.push("--rsh=ssh");
    }

    if ( options.recursive === true ) {
        args.push("--recursive");
    }

    if ( options.syncDest === true ) {
        args.push("--delete");
        args.push("--delete-excluded");
    }

    if ( options.dryRun === true ) {
        args.push("--dry-run");
        args.push("--verbose");
        args.push("--stats");
    }

    if ( typeof options.exclude !== "undefined" && util.isArray(options.exclude) ) {
        options.exclude.forEach(function (value,index) {
            args.push("--exclude="+value);
        });
    }

    switch ( options.compareMode ) {
        case "sizeOnly":
            args.push("--size-only");
            break;
        case "checksum":
            args.push("--checksum");
            break;
    }

    if ( typeof options.args !== "undefined" && util.isArray(options.args) ) {
        args = _.union(args,options.args);
    }

    args = _.unique(args);

    var cmd = "rsync "+args.join(" ");

    try {
        var process = spawn("rsync",args);
        var stdoutBuffer = "";
        var stderrBuffer = "";

        process.stdout.on("data", function (data) {
            stdoutBuffer += data;
        });

        process.stderr.on("data", function (data) {
            stderrBuffer += data;
        });

        process.on("exit", function (code) {
            callback(code===0?null:new Error("rsync exited with code "+code+". "+stderrBuffer),stdoutBuffer,stderrBuffer,cmd);
        });
    } catch (error) {
        callback(error,null,null,cmd);
    }
};<commit_msg>Fixed bug where rsyncwrapper was directly manipulating the dest field in the options object. This was causing problems with use cases like grunt watch where the options object was being persisted across rsyncwrapper invocations.<commit_after>"use strict";

var spawn = require("child_process").spawn;
var util = require("util");
var _ = require("lodash");

exports.rsync = function (options,callback) {

    options = options || {};

    if ( typeof options.src === "undefined" ) {
        throw(new Error("'src' directory is missing from options"));
    }

    if ( typeof options.dest === "undefined" ) {
        throw(new Error("'dest' directory is missing from options"));
    }

    var dest = options.dest;

    if ( typeof options.host !== "undefined" ) {
        dest = options.host+":"+options.dest;
    }

    var args = [options.src,dest];

    if ( typeof options.host !== "undefined" ) {
        args.push("--rsh=ssh");
    }

    if ( options.recursive === true ) {
        args.push("--recursive");
    }

    if ( options.syncDest === true ) {
        args.push("--delete");
        args.push("--delete-excluded");
    }

    if ( options.dryRun === true ) {
        args.push("--dry-run");
        args.push("--verbose");
        args.push("--stats");
    }

    if ( typeof options.exclude !== "undefined" && util.isArray(options.exclude) ) {
        options.exclude.forEach(function (value,index) {
            args.push("--exclude="+value);
        });
    }

    switch ( options.compareMode ) {
        case "sizeOnly":
            args.push("--size-only");
            break;
        case "checksum":
            args.push("--checksum");
            break;
    }

    if ( typeof options.args !== "undefined" && util.isArray(options.args) ) {
        args = _.union(args,options.args);
    }

    args = _.unique(args);

    var cmd = "rsync "+args.join(" ");

    try {
        var process = spawn("rsync",args);
        var stdoutBuffer = "";
        var stderrBuffer = "";

        process.stdout.on("data", function (data) {
            stdoutBuffer += data;
        });

        process.stderr.on("data", function (data) {
            stderrBuffer += data;
        });

        process.on("exit", function (code) {
            callback(code===0?null:new Error("rsync exited with code "+code+". "+stderrBuffer),stdoutBuffer,stderrBuffer,cmd);
        });
    } catch (error) {
        callback(error,null,null,cmd);
    }
};
{'fraction_non_alphanumeric': 0.16755831371709823, 'fraction_numerical': 0.00042799058420714745, 'mean_word_length': 2.223448275862069, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '7178264', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1331, 'n_words': 292}