copy source file to destination file or path

@throws PageException
181374
private void actionDelete() throws PageException {
	checkFile(pageContext, securityManager, file, serverPassword, false, false, false, false);
	setACL(pageContext, file, acl);
	try {
	    if (!file.delete()) throw new ApplicationException("can't delete file [" + file + "]");
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    throw new ApplicationException(t.getMessage());
	}
    }
48705
private void doDelete() throws PageException, SearchException {
	required("index", action, "collection", collection);
	if (type != SearchIndex.TYPE_CUSTOM) required("index", action, "key", key);

	// no type defined
	if (type == -1) {
	    if (query != null) {
		type = SearchIndex.TYPE_CUSTOM;
	    }
	    else {
		Resource file = null;
		try {
		    file = ResourceUtil.toResourceExisting(pageContext, key);
		    pageContext.getConfig().getSecurityManager().checkFileLocation(file);
		}
		catch (ExpressionException e) {}

		if (file != null && file.exists() && file.isFile()) type = SearchIndex.TYPE_FILE;
		else if (file != null && file.exists() && file.isDirectory()) type = SearchIndex.TYPE_PATH;
		else {
		    try {
			new URL(key);
			type = SearchIndex.TYPE_URL;
		    }
		    catch (MalformedURLException e) {}
		}
	    }
	}

	collection.deleteIndex(pageContext, key, type, query);
    }
1085816
public function _savePageSource($filename)
    {
        if (!isset($this->webDriver)) {
            $this->debug('WebDriver::_savePageSource method has been called when webDriver is not set');
            return;
        }
        try {
            file_put_contents($filename, $this->webDriver->getPageSource());
        } catch (\Exception $e) {
            $this->debug('Unable to retrieve source page from Selenium : ' . $e->getMessage());
        }
    }
399425
public static void copyRecursively(Path source, Path destination) throws IOException {
        if (Files.isDirectory(source))
        {
            Files.createDirectories(destination);
            final Set<Path> sources = listFiles(source);

            for (Path srcFile : sources)
            {
                Path destFile = destination.resolve(srcFile.getFileName());
                copyRecursively(srcFile, destFile);
            }
        }
        else
        {
            Files.copy(source, destination, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
        }
    }
200499
public static File copyFile(File src, File dest, StandardCopyOption... options) throws IORuntimeException {
		// check
		Assert.notNull(src, "Source File is null !");
		if (false == src.exists()) {
			throw new IORuntimeException("File not exist: " + src);
		}
		Assert.notNull(dest, "Destination File or directiory is null !");
		if (equals(src, dest)) {
			throw new IORuntimeException("Files '{}' and '{}' are equal", src, dest);
		}
		return copyFile(src.toPath(), dest.toPath(), options).toFile();
	}
719669
public static void actionMove(PageContext pageContext, lucee.runtime.security.SecurityManager securityManager, Resource source, String strDestination, int nameconflict,
	    String serverPassword, Object acl, int mode, String attributes) throws PageException {
	if (nameconflict == NAMECONFLICT_UNDEFINED) nameconflict = NAMECONFLICT_OVERWRITE;

	if (source == null) throw new ApplicationException("attribute source is not defined for tag file");
	if (StringUtil.isEmpty(strDestination)) throw new ApplicationException("attribute destination is not defined for tag file");

	Resource destination = toDestination(pageContext, strDestination, source);

	securityManager.checkFileLocation(pageContext.getConfig(), source, serverPassword);
	securityManager.checkFileLocation(pageContext.getConfig(), destination, serverPassword);
	if (source.equals(destination)) return;

	// source
	if (!source.exists()) throw new ApplicationException("source file [" + source.toString() + "] doesn't exist");
	else if (!source.isFile()) throw new ApplicationException("source file [" + source.toString() + "] is not a file");
	else if (!source.isReadable() || !source.isWriteable()) throw new ApplicationException("no access to source file [" + source.toString() + "]");

	// destination
	if (destination.isDirectory()) destination = destination.getRealResource(source.getName());
	if (destination.exists()) {
	    // SKIP
	    if (nameconflict == NAMECONFLICT_SKIP) return;
	    // OVERWRITE
	    else if (nameconflict == NAMECONFLICT_OVERWRITE) destination.delete();
	    // MAKEUNIQUE
	    else if (nameconflict == NAMECONFLICT_MAKEUNIQUE) destination = makeUnique(destination);
	    // ERROR
	    else throw new ApplicationException("destiniation file [" + destination.toString() + "] already exist");
	}

	setACL(pageContext, destination, acl);
	try {
	    source.moveTo(destination);

	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    throw new ApplicationException(t.getMessage());
	}

	setMode(destination, mode);
	setAttributes(destination, attributes);
    }
466584
private AFTPClient actionPutFile() throws IOException, PageException {
	required("remotefile", remotefile);
	required("localfile", localfile);

	AFTPClient client = getClient();
	Resource local = ResourceUtil.toResourceExisting(pageContext, localfile);// new File(localfile);
	// if(failifexists && local.exists()) throw new ApplicationException("File ["+local+"] already
	// exist, if you want to overwrite, set attribute
	// failIfExists to false");
	InputStream is = null;

	try {
	    is = IOUtil.toBufferedInputStream(local.getInputStream());
	    client.setFileType(getType(local));
	    client.storeFile(remotefile, is);
	}
	finally {
	    IOUtil.closeEL(is);
	}
	writeCfftp(client);

	return client;
    }
993481
public static void copyDirs(Path source, Path target, CopyOption... options) throws IOException {
        if (Files.notExists(target)) {
            Files.createDirectory(target);
        }

        logger.debug("  --> Copying resources from [{}]", source);
        if (Files.notExists(source)) {
            throw new RuntimeException(source + " doesn't seem to exist.");
        }

        Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new InternalFileVisitor(source, target, options));

        logger.debug("  --> Resources ready in [{}]", target);
    }
77725
private function copyFile(
        FilesystemInterface $source,
        FilesystemInterface $destination,
        $path
    ) {
        $destination->put(
            $path,
            $source->read($path)
        );
    }
660535
private void doGetDatasources() throws PageException {

	Map ds = config.getDataSourcesAsMap();
	Iterator it = ds.keySet().iterator();
	lucee.runtime.type.Query qry = new QueryImpl(new String[] { "name", "host", "classname", "bundleName", "bundleVersion", "dsn", "DsnTranslated", "database", "port",
		"timezone", "username", "password", "passwordEncrypted", "readonly", "grant", "drop", "create", "revoke", "alter", "select", "delete", "update", "insert",
		"connectionLimit", "openConnections", "connectionTimeout", "clob", "blob", "validate", "storage", "customSettings", "metaCacheTimeout" }, ds.size(), "query");

	int row = 0;

	while (it.hasNext()) {
	    Object key = it.next();
	    DataSource d = (DataSource) ds.get(key);
	    row++;

	    qry.setAt(KeyConstants._name, row, key);
	    qry.setAt(KeyConstants._host, row, d.getHost());
	    qry.setAt("classname", row, d.getClassDefinition().getClassName());
	    qry.setAt("bundleName", row, d.getClassDefinition().getName());
	    qry.setAt("bundleVersion", row, d.getClassDefinition().getVersionAsString());
	    qry.setAt("dsn", row, d.getDsnOriginal());
	    qry.setAt("database", row, d.getDatabase());
	    qry.setAt(KeyConstants._port, row, d.getPort() < 1 ? "" : Caster.toString(d.getPort()));
	    qry.setAt("dsnTranslated", row, d.getDsnTranslated());
	    qry.setAt("timezone", row, toStringTimeZone(d.getTimeZone()));
	    qry.setAt(KeyConstants._password, row, d.getPassword());

	    qry.setAt("passwordEncrypted", row, ConfigWebUtil.encrypt(d.getPassword()));
	    qry.setAt(KeyConstants._username, row, d.getUsername());
	    qry.setAt(KeyConstants._readonly, row, Caster.toBoolean(d.isReadOnly()));
	    qry.setAt(KeyConstants._select, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_SELECT)));
	    qry.setAt(KeyConstants._delete, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DELETE)));
	    qry.setAt(KeyConstants._update, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_UPDATE)));
	    qry.setAt(KeyConstants._create, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_CREATE)));
	    qry.setAt(KeyConstants._insert, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
	    qry.setAt(KeyConstants._drop, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DROP)));
	    qry.setAt(KeyConstants._grant, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_GRANT)));
	    qry.setAt(KeyConstants._revoke, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_REVOKE)));
	    qry.setAt(KeyConstants._alter, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_ALTER)));
	    int oc = config.getDatasourceConnectionPool().openConnections(key.toString());
	    qry.setAt("openConnections", row, oc < 0 ? 0 : oc);
	    qry.setAt("connectionLimit", row, d.getConnectionLimit() < 1 ? "" : Caster.toString(d.getConnectionLimit()));
	    qry.setAt("connectionTimeout", row, d.getConnectionTimeout() < 1 ? "" : Caster.toString(d.getConnectionTimeout()));
	    qry.setAt("customSettings", row, d.getCustoms());
	    qry.setAt("blob", row, Boolean.valueOf(d.isBlob()));
	    qry.setAt("clob", row, Boolean.valueOf(d.isClob()));
	    qry.setAt("validate", row, Boolean.valueOf(d.validate()));
	    qry.setAt("storage", row, Boolean.valueOf(d.isStorage()));
	    qry.setAt("metaCacheTimeout", row, Caster.toDouble(d.getMetaCacheTimeout()));

	}
	pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
    }
321771
public void copyFile(String source, String target) {

        try {
            CmsFileUtil.copy(m_configRfsPath + source, m_configRfsPath + target);
        } catch (IOException e) {
            m_errors.add("Could not copy " + source + " to " + target + " \n");
            m_errors.add(e.toString() + "\n");
        }
    }
436708
private void actionAppend() throws PageException {
	if (output == null) throw new ApplicationException("attribute output is not defined for tag file");
	checkFile(pageContext, securityManager, file, serverPassword, createPath, true, false, true);

	setACL(pageContext, file, acl);
	try {
	    if (!file.exists()) file.createNewFile();
	    String content = Caster.toString(output);
	    if (fixnewline) content = doFixNewLine(content);
	    if (addnewline) content += SystemUtil.getOSSpecificLineSeparator();
	    IOUtil.write(file, content, CharsetUtil.toCharset(charset), true);

	}
	catch (UnsupportedEncodingException e) {
	    throw new ApplicationException("Unsupported Charset Definition [" + charset + "]", e.getMessage());
	}
	catch (IOException e) {
	    throw new ApplicationException("can't write file", e.getMessage());
	}
	setMode(file, mode);
	setAttributes(file, attributes);
    }
1007520
public static boolean copy(File source, File destination) {
        boolean result = true;
        if (source.isDirectory()) {
            if (destination.exists()) {
                result = result && destination.isDirectory();
            } else {
                result = result && destination.mkdirs();
            }
            File[] children = source.listFiles();
            for (File element : children) {
                result =
                        result
                                && copy(new File(source, element.getName()),
                                        new File(destination, element.getName()));
            }
            return result;
        } else {
            try {
                InputStream in = new FileInputStream(source);
                OutputStream out = new FileOutputStream(destination);
                result = result && copy(in, out);
                in.close();
                out.close();
                return result;
            } catch (IOException e) {
                return false;
            }
        }
    }
585922
private static void copyToLocal(Metadata src, Path dst) throws IOException {
    FileChannel dstCh = FileChannel.open(
        dst, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);
    ReadableByteChannel srcCh = FileSystems.open(src.resourceId());
    long srcSize = src.sizeBytes();
    long copied = 0;
    do {
      copied += dstCh.transferFrom(srcCh, copied, srcSize - copied);
    } while (copied < srcSize);
    dstCh.close();
    srcCh.close();
    Preconditions.checkState(copied == srcSize);
  }
382960
public static void copy(InputStream source, File destination) throws IOException {
        OutputStream output = null;

        try {
            output = new FileOutputStream(destination);
            copy(source, output);
        } finally {
            closeQuietly(output);
        }
    }
778175
protected function copyFiles()
    {
        $skeletonFinder = new SkeletonFinder($this->lookupPaths);
        $sourcePath = $skeletonFinder->findByName($this->skeletonName)->getRealpath();

        $finder = $this->getFinderForFilesToCopy($sourcePath);

        foreach ($finder as $file) {
            $targetFilePath = $this->targetPath.DIRECTORY_SEPARATOR.$file->getRelativePathname();
            $targetFilePath = $this->twigStringRenderer->renderToString($targetFilePath, $this->data);

            $this->fs->copy($file->getRealpath(), $targetFilePath, $this->overwriteEnabled);

            $msg = '[copy] '.$file->getRealpath().' => '.$targetFilePath;

            if ($this->reportingEnabled) {
                $this->report[] = $msg;
            }
        }
    }
1083396
void copyTo(final File destinationFolder) throws IOException {
    for (final File f : this.theFiles) {
      final File destinationFile = new File(destinationFolder, f.getName());
      Files.copy(f.toPath(), destinationFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
    }
  }