{"size": 1095, "ext": "js", "max_stars_repo_path": "lib/rsyncService.js", "max_stars_repo_name": "cptavatar/node-sync-logs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/rsyncService.js", "max_issues_repo_name": "cptavatar/node-sync-logs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/rsyncService.js", "max_forks_repo_name": "cptavatar/node-sync-logs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.7073170732, "max_line_length": 65, "alphanum_fraction": 0.4401826484}
var Rsync = require('rsync');

/**
 * Module to handle rsync operations
 */





module.exports = function (exec, log) {
    return {
        'createCommand': function createCommand(config) {
            var i, x, tempPath, splitPath, rsync = new Rsync()
                .flags('rtvu')
                .set('copy-dirlinks')
                .source(config.server)
                .destination(config.destDir);

            for (i in config.paths) {
                splitPath = config.paths[i].split('/');
                tempPath = '';
                for (x in splitPath) {
                    if (tempPath) {
                        tempPath = tempPath + '/' + splitPath[x];
                    } else {
                        tempPath = splitPath[x];
                    }
                    rsync.include(tempPath);
                }
            }
            rsync.exclude("*");
            return rsync.command();
        },

        'syncLogs': function syncLogs(config) {
            log.info("Running rsync...");
            exec.execSync(this.createCommand(config));
        }
    }
}