Allow transform stream to add files during transformation
process to the copy/concat queue
Path in cwd is required for security reason

@param {Array|String} sources
@param {String}       dest
507674
function addFiles(sources, dest, options) {
      var opt = _.extend({}, defaultOptions, options || {});

      if(_.isString(sources)) {
        sources = [sources];
      }

      if(!inCwd(dest) || _.any(sources, function(src) {
        return !inCwd(src);
      })) {
        grunt.verbose.writeln('Ignore %s to %s: not in CWD.');
        return;
      }

      return addToQueueCopy(sources, dest, opt);
    }
802856
function mapSources (sourceMap, mapCallback) {
  let chain = Promise.resolve()
  function pushChain (path, index, arr) {
    chain = chain
      .then(() => mapCallback(path))
      .then(replacement => {
        arr[index] = replacement || path
      })
  }
  if (sourceMap.sources) {
    sourceMap.sources.forEach(pushChain)
  }
  if (sourceMap.sections) {
    sourceMap.sections.forEach(section => {
      if (section.map && section.map.sources) {
        section.map.sources.forEach(pushChain)
      }
    })
  }
  return chain.then(() => sourceMap)
}
548905
function write(destPath, options) {
  var debug = require('../debug').spawn('write');

  debug(function() { return 'destPath'; });
  debug(function() { return destPath; });

  debug(function() { return 'original options';});
  debug(function() { return options; });

  if (options === undefined && typeof destPath !== 'string') {
    options = destPath;
    destPath = undefined;
  }
  options = options || {};

  // set defaults for options if unset
  if (options.includeContent === undefined) {
    options.includeContent = true;
  }
  if (options.addComment === undefined) {
    options.addComment = true;
  }
  if (options.charset === undefined) {
    options.charset = 'utf8';
  }

  debug(function() { return 'derrived options'; });
  debug(function() { return options; });

  var internals = internalsInit(destPath, options);

  function sourceMapWrite(file, encoding, callback) {
    if (file.isNull() || !file.sourceMap) {
      this.push(file);
      return callback();
    }

    if (file.isStream()) {
      return callback(new Error(utils.PLUGIN_NAME + '-write: Streaming not supported'));
    }

    // fix paths if Windows style paths
    file.sourceMap.file = unixStylePath(file.relative);

    internals.setSourceRoot(file);
    internals.loadContent(file);
    internals.mapSources(file);
    internals.mapDestPath(file, this);

    this.push(file);
    callback();
  }

  return through.obj(sourceMapWrite);
}
469596
function gulpSymlink(dest, options) {

  options = typeof options == 'object' ? options : {}
  options.force = options.force === undefined ? false : options.force

  if (!dest) {
    throw new PluginError({plugin: PLUGIN_NAME, message: "Missing destination link"})
  }

  if(dest instanceof Array) {
    //copy array because we'll shift values
    var destinations = dest.slice()
  }

  var stream = through.obj(function(source, enc, callback) {

    var self = this, symlink

    //resolving absolute path from source
    source.path = p.resolve(source.cwd, source.path)
    // source.relative = p.relative(source.cwd, source.path)

    //Array of destinations is passed
    symlink = destinations !== undefined ? destinations.shift() : dest

    //if dest is a function simply call it
    symlink = typeof dest == 'function' ? dest(source) : symlink

    //is the previous result a File instance ?
    symlink = symlink instanceof File ? symlink : new File({path: symlink})

    //resolving absolute path from dest
    symlink.path = p.resolve(symlink.cwd, symlink.path)

    //relative path between source and link
    var relative_symlink_source = p.relative(p.dirname(symlink.path), source.path)

    //check if the destination path exists
    var exists = existsSync(symlink.path)

    //No force option, we can't override!
    if(exists && !options.force) {
      this.emit('error', new PluginError({plugin: PLUGIN_NAME, message: 'Destination file exists ('+dest+') - use force option to replace'}))
      this.push(source)
      return callback()

    }

    //remove destination if force option
    if(exists && options.force === true)
      rm.sync(symlink.path) //I'm aware that this is bad \o/

    //create destination directories
    if(!fs.existsSync(p.dirname(symlink.path)))
      mkdirp.sync(p.dirname(symlink.path))

    //this is a windows check as specified in http://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback
    source.stat = fs.statSync(source.path)

    fs.symlink(options.relative ? relative_symlink_source : source.path, symlink.path, source.stat.isDirectory() ? 'dir' : 'file', function(err) {

      if(err)
        self.emit('error', new PluginError({plugin: PLUGIN_NAME, message: err}))
      else
        gutil.log(PLUGIN_NAME + ':', gutil.colors.yellow(symlink.path), '→', gutil.colors.blue(options.relative ? relative_symlink_source : source.path))

      self.push(source)
      callback()
    })
  })

  return stream
}
610521
function (paths, dest, options, cb) {
  'use strict';

  // copy the entire pattern directory, as-is, to our destination directory
  fs.copy(String(paths.folder), dest, function (err) {
    if (err && err.code !== 'ENOENT') {return log.error(err); }

    // success in cloning the directory
    log.info(paths.directory + ' pattern cloned into ' + dest);

    // create the cloned pattern's data file's path
    var clonedPatternYmlFile = paths.relative;

    // open the cloned pattern's data file
    var clonedPatternYml = fs.readFileSync(clonedPatternYmlFile, {encoding: 'utf8'});

    // get metadata from the data file
    var clonedPatternObject = utility.convertYamlToObject(clonedPatternYml);

    // new file contents
    var newDataFileContents = utility.convertObjectToYaml(addCloneSource(paths, clonedPatternObject));

    // overwrite the cloned pattern's data file with the adjusted contents
    fs.writeFile(clonedPatternYmlFile, newDataFileContents, function (err) {
      if (err) { throw err; }
      log.info(clonedPatternYmlFile + ' cloned source added to ' + options.dataFileName);
      cb();
    });
  });
}
294782
def copy(source, dest):
    
    logger.info("copying {} -> {}".format(source, dest))

    return client.copy(source, dest)
1260983
public static function copyResources($dest, $force, $filename_path, $debug)
    {
        if (file_exists($filename_path)) {
            $destfolder = basename($filename_path);
            if (!file_exists(WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) || $debug || $force) {
                if (is_dir($filename_path)) {
                    self::copyr($filename_path, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder);
                } else {
                    if (@copy($filename_path, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) === FALSE) {
                        throw new ConfigException("Can't copy " . $filename_path . " to " . WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder);
                    }
                }
            }
        }
    }
1285346
function move(src, dest) {
	return rename(src, dest).catch((err) => {
		// try copying
		return copy(src, dest).then(() => {
			// delete source
			return unlink(src);
		});
	});
}
1091270
function(source, dest) {
        if ((source && dest)) {
            OpenLayers.Projection.transform(
                this, source, dest); 
            this.bounds = null;
        }       
        return this;
    }
211339
public static Map<String, Object> putAllIfNew(Map<String, Object> dest, Map<String, Object> source)
    {
    	if (dest == null)
    		return source;
    	if (source == null)
    	    return dest;
    	for (String key : source.keySet())
    	{
    		if (dest.get(key) == null)
    			dest.put(key, source.get(key));
    	}
    	return dest;
    }
789441
public function copy($source, $dest)
    {
        if (!is_dir($source)) {
            $dest = $this->mkdir($dest);
            $files = $this->readDir($source);

            foreach ($files as $file) {
                if (is_dir($source.'/'.$file)) {
                    $this->copy($source.'/'.$file, $dest.'/'.$file);
                } else {
                    copy($source.'/'.$file, $dest.'/'.$file);
                }
            }
        } elseif (is_file($source)) {
            return copy($source, $dest);
        }

        return true;
    }
18067
function(src, dest){
      self.logger.info('generating '+dest); 
      fs.createReadStream(src).pipe(fs.createWriteStream(dest)); 
    }
682168
function onNextTransform (transform, next) {
      // check if we should handle this filePath
      function shouldProcess (filePath, done) {
        done(!!multimatch(filePath, transform.pattern, transform.opts).length)
      }

      // transform the path
      function process (filePath, complete) {
        var filename = path.basename(filePath),
            pathParts = path.dirname(filePath).split(path.sep)

        // we'll get an empty arrary if we overslice
        pathParts = pathParts.slice(transform.by)
        pathParts.push(filename)

        var newPath = pathParts.join(path.sep),
            fileData = files[filePath]

        // don't need the old fileData anymore,
        // since we are re-adding with the new path
        delete files[filePath]
        files[newPath] = fileData

        complete()
      }

      // we do this for each option as the last may have modified the collection
      async.filter(Object.keys(files), shouldProcess, function (results) {
        async.each(results, process, next)
      })
    }
1054073
function copyFiles(srcfile, dstfile, callback) {
        var fs = require("fs");
        var rs = fs.createReadStream(srcfile);
        var ws = fs.createWriteStream(dstfile);
        rs.on("data", function(d) {
            ws.write(d);
        });
        rs.on("end", function() {
            ws.end();
            callback(true);
        });
    }
1286196
function(folder, dest) {
		try {
			fs.mkdirSync(dest, '0755');
		} catch (e) {}
		var files = fs.readdirSync(folder);
		var indexFile = templatesManager.getFolderIndex(files);
		logger.debug('Index file for "%s": "%s"', folder, indexFile);
		files.forEach(function(file) {
			if (config.exclude.indexOf(file) === -1) {
				var curPath = path.join(folder, file);
				if (fs.statSync(curPath).isDirectory()) {
					walk(curPath, path.join(dest, file));
				} else {
					if (['.md', '.markdown'].indexOf(path.extname(file).toLowerCase()) !== -1) {
						var isIndex = (file === indexFile);
						filesToRender[curPath] = {
							filename: file,
							path: curPath,
							versions: templatesManager.getVersions(curPath, 'template', isIndex),
							isIndex: isIndex
						};
					} else if (config.media.indexOf(path.extname(file).toLowerCase().substr(1)) !== -1) {
						logger.log('Copy "%s" to "%s"', curPath, path.join(dest, path.basename(curPath)));
						fs.copy(curPath, path.join(dest, path.basename(curPath)), {replace: true}, function(err) {
							if (err) {
								logger.error('Problem while copying media file "%s" to "%s": "%s"', curPath, path.join(dest, path.basename(curPath)), err);
							}
						});
					}
				}
			} else {
				logger.debug('Excluded:', file);
			}
		});
	}
891648
public static void copyFiles(File src, File dest) throws IOException {
        if (src.isDirectory()) {
            dest.mkdirs();
            String list[] = src.list();
            for (String fileName : list) {
                String dest1 = dest.getPath() + "/" + fileName;
                String src1 = src.getPath() + "/" + fileName;
                // i.e: avoid .svn directory
                File src1_ = new File(src1);
                File dest1_ = new File(dest1);
                if (!src1_.isHidden()) {
                    copyFiles(src1_, dest1_);
                }
            }
        } else {

            FileInputStream fin = new FileInputStream(src);
            FileOutputStream fout = new FileOutputStream(dest);
            int c;
            while ((c = fin.read()) >= 0) {
                fout.write(c);
            }
            fin.close();
            fout.close();
        }
    }
1185084
public static boolean copyMerge(FileSystem srcFS, Path srcDir, 
                                  FileSystem dstFS, Path dstFile, 
                                  boolean deleteSource,
                                  Configuration conf, String addString) throws IOException {
    dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false);

    if (!srcFS.getFileStatus(srcDir).isDir())
      return false;
   
    OutputStream out = dstFS.create(dstFile);
    
    try {
      FileStatus contents[] = srcFS.listStatus(srcDir);
      for (int i = 0; i < contents.length; i++) {
        if (!contents[i].isDir()) {
          InputStream in = srcFS.open(contents[i].getPath());
          try {
            IOUtils.copyBytes(in, out, conf, false);
            if (addString!=null)
              out.write(addString.getBytes("UTF-8"));

          } finally {
            in.close();
          }
        }
      }
    } finally {
      out.close();
    }


    if (deleteSource) {
      return srcFS.delete(srcDir, true);
    } else {
      return true;
    }
  }