lib/init/functions.js
function mcFile(type, source, target, cb) {

	var targetDir,
	    bin,
	    cmd;

	if (type == 'cp' || type == 'copy') {
		bin = '/bin/cp';
	} else if (type == 'mv' || type == 'move') {
		bin = '/bin/mv';
	}

	// We assume the last piece of the target is the file name
	// Split the string by slashes
	targetDir = target.split('/');

	// Remove the last piece
	targetDir.splice(targetDir.length-1, 1);

	// Join it again
	targetDir = targetDir.join('/');

	// Make sure the target directory exists
	alchemy.createDir(targetDir, function ensuredDir(err) {

		if (err) {
			return cb(err);
		}

		spawnQueue.add(function queuecp(done) {

			var options = [];

			if (process.platform == 'linux') {
				options = ['--no-target-directory', source, target];
			} else {
				if (source.endsWith('/')) {
					source = source.slice(0, -1);
				}

				if (target.endsWith('/')) {
					target = target.slice(0, -1);
				}

				options = [source, target];
			}

			cmd = child.execFile(bin, options);

			cmd.on('exit', function onExit(code, signal) {

				var message;

				done();

				if (code > 0) {
					message = 'File "' + type + '" operation failed:\n';
					message += bin + ' ' + options.join(' ');

					cb(new Error(message));
				} else {
					cb(null);
				}
			});
		});
	});
}
function mcFile(type, source, target, cb) {

	var targetDir,
	    bin,
	    cmd;

	if (type == 'cp' || type == 'copy') {
		bin = '/bin/cp';
	} else if (type == 'mv' || type == 'move') {
		bin = '/bin/mv';
	}

	// We assume the last piece of the target is the file name
	// Split the string by slashes
	targetDir = target.split('/');

	// Remove the last piece
	targetDir.splice(targetDir.length-1, 1);

	// Join it again
	targetDir = targetDir.join('/');

	// Make sure the target directory exists
	alchemy.createDir(targetDir, function ensuredDir(err) {

		if (err) {
			return cb(err);
		}

		spawnQueue.add(function queuecp(done) {

			var options = [];

			if (process.platform == 'linux') {
				options = ['--no-target-directory', source, target];
			} else {
				if (source.endsWith('/')) {
					source = source.slice(0, -1);
				}

				if (target.endsWith('/')) {
					target = target.slice(0, -1);
				}

				options = [source, target];
			}

			cmd = child.execFile(bin, options);

			cmd.on('exit', function onExit(code, signal) {

				var message;

				done();

				if (code > 0) {
					message = 'File "' + type + '" operation failed:\n';
					message += bin + ' ' + options.join(' ');

					cb(new Error(message));
				} else {
					cb(null);
				}
			});
		});
	});
}
function mcFile ( type , source , target , cb ) { var targetDir , bin , cmd ; if ( type == 'cp' || type == 'copy' ) { bin = '/bin/cp' ; } else if ( type == 'mv' || type == 'move' ) { bin = '/bin/mv' ; } // We assume the last piece of the target is the file name // Split the string by slashes targetDir = target . split ( '/' ) ; // Remove the last piece targetDir . splice ( targetDir . length - 1 , 1 ) ; // Join it again targetDir = targetDir . join ( '/' ) ; // Make sure the target directory exists alchemy . createDir ( targetDir , function ensuredDir ( err ) { if ( err ) { return cb ( err ) ; } spawnQueue . add ( function queuecp ( done ) { var options = [ ] ; if ( process . platform == 'linux' ) { options = [ '--no-target-directory' , source , target ] ; } else { if ( source . endsWith ( '/' ) ) { source = source . slice ( 0 , - 1 ) ; } if ( target . endsWith ( '/' ) ) { target = target . slice ( 0 , - 1 ) ; } options = [ source , target ] ; } cmd = child . execFile ( bin , options ) ; cmd . on ( 'exit' , function onExit ( code , signal ) { var message ; done ( ) ; if ( code > 0 ) { message = 'File "' + type + '" operation failed:\n' ; message += bin + ' ' + options . join ( ' ' ) ; cb ( new Error ( message ) ) ; } else { cb ( null ) ; } } ) ; } ) ; } ) ; }
Move or copy a file

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.0.1
@version  1.0.5

@param    {String}   source     Origin path
@param    {String}   target     Target path
@param    {Function} cb
Move or copy a file