/**
 * Link prototype files unless already exists.
 * @function ci.worker.linkPrototypeFiles
 * @param {object} config - Task configuration.
 * @param {string} [config.prototypeBaseDir] - Prototype base directory.
 * @param {string} config.pattern - File name glob patterns.
 * @param {string} config.ignore - Ignore  filename pattern. Glob.
 * @param {string} [config.destDir=apeman.current.basedir()] - Destination directory name.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */
var path = require('path'),
    lib = require('../../lib'),
    file = lib.file,
    inheritPrototypeFiles = require('./_inherit_prototype_files');

exports = module.exports = function (config, callback) {
    inheritPrototypeFiles(config, exports._doCopy, callback);
};

exports._doCopy = function (src, dest, callback) {
    file.mkdirP(path.dirname(dest), function (err) {
        if (err) {
            callback(err);
            return;
        }
        file.copyFile(src, dest, function (err) {
            callback(err);
        });
    });
};