Copy file `$file_path` if it exists to `$target_path`

@param   string  $file_path
@param   string  $target_path
@param   bool    $force
@param   array   $logs   Logs registry passed by reference
@return  bool
180033
public static function copy($file_path = null, $target_path = null, $force = false, array &$logs = array())
    {
        if (is_null($file_path) || is_null($target_path)) {
            return null;
        }
        if (!file_exists($file_path)) {
            $logs[] = sprintf('File path "%s" to copy was not found.', $file_path);
            return false;
        }
        $target_dir = dirname($target_path);
        $ok = (!file_exists($target_dir) && true===$force) ? Directory::create($target_dir) : true;
        if ($ok) {
            if (!file_exists($target_path) || true===$force) {
                if (copy($file_path, $target_path)) {
                    return true;
                } else {
                    $logs[] = sprintf('Can not copy file "%s" to "%s".', $file_path, $target_path);
                }
            } else {
                $logs[] = sprintf('Can not over-write target file "%s" by copy (use param `$force=true`).', $target_path);
            }
        } else {
            $logs[] = sprintf('Can not create target directory "%s" for copy.', $target_dir);
        }
        return false;
    }
602552
def copy_resources_to_log_dir(log_dir):
        """"""
        css_path = resource_filename(Requirement.parse("egat"), "/egat/data/default.css")
        header_path = resource_filename(Requirement.parse("egat"), "/egat/data/egat_header.png")
        shutil.copyfile(css_path, log_dir + "/style.css")
        shutil.copyfile(header_path, log_dir + "/egat_header.png")

        return log_dir + os.sep + "style.css"
66260
protected function remove($path, $force = false, $recursive = false) {
		$stat = $this->stat($path);
		$stat['realpath'] = $path;
		$this->rmTmb($stat);
		$this->clearcache();
	
		if (empty($stat)) {
			return $this->setError(elFinder::ERROR_RM, $this->_path($path), elFinder::ERROR_FILE_NOT_FOUND);
		}
	
		if (!$force && !empty($stat['locked'])) {
			return $this->setError(elFinder::ERROR_LOCKED, $this->_path($path));
		}
	
		if ($stat['mime'] == 'directory') {
			if (!$recursive && !$this->_rmdir($path)) {
				return $this->setError(elFinder::ERROR_RM, $this->_path($path));
			}
		} else {
			if (!$recursive && !$this->_unlink($path)) {
				return $this->setError(elFinder::ERROR_RM, $this->_path($path));
			}
		}
	
		$this->removed[] = $stat;
		return true;
	}
785650
public function write($file_content, $rel_path){
		$path = $this->setDir($rel_path);
		return $path && file_put_contents($path, $file_content)
			? $path
			: false;
	}
1073920
private function copy($source, $target)
    {
        $files = $this->listFiles($source, $target);

        foreach ($files as $newPath => $oldPath) {
            if (!file_exists($newPath)) {
                if (is_dir($oldPath)) {
                    mkdir($newPath, 0755, true);
                } else {
                    copy($oldPath, $newPath);
                }
            }
        }
    }
1337940
protected function _copy($source, $targetDir, $name) {
		$res = false;
		
		if ($this->tmp) {
			$local  = $this->getTempFile();
			$target = $targetDir.DIRECTORY_SEPARATOR.$name;

			if (ftp_get($this->connect, $local, $source, FTP_BINARY)
			&& ftp_put($this->connect, $target, $local, $this->ftpMode($target))) {
				$res = $target;
			}
			@unlink($local);
		}
		
		return $res;
	}
79607
public static function copy(string $path, string $to, string $type, bool $symlink = false):int
    {
        try {
            if ($symlink != false) {
                @symlink($path, $to);
            } elseif ($symlink == false && $type == "directory") {
                self::recursiveCopy($path, $to);
            } elseif ($symlink == false && $type == "file") {
                copy($path, $to);
            } else {
                throw new \Exception("Server Error on Copy: Element type is not regonized");
            }
        } catch (\Exception $exception) {
            throw new \Exception("Server Error : Cannot move $path to $to => ".$exception);
        }

        return (1);
    }
322990
protected void uploadDirectory(final FTPClient ftpClient, final String sourceDirectoryPath,
                                   final String targetDirectoryPath, final String logPrefix) throws IOException {
        log.info(String.format(UPLOAD_DIR, logPrefix, sourceDirectoryPath, targetDirectoryPath));
        final File sourceDirectory = new File(sourceDirectoryPath);
        final File[] files = sourceDirectory.listFiles();
        if (files == null || files.length == 0) {
            log.info(String.format("%sEmpty directory at %s", logPrefix, sourceDirectoryPath));
            return;
        }

        // Make sure target directory exists
        final boolean isTargetDirectoryExist = ftpClient.changeWorkingDirectory(targetDirectoryPath);
        if (!isTargetDirectoryExist) {
            ftpClient.makeDirectory(targetDirectoryPath);
        }

        final String nextLevelPrefix = logPrefix + "..";
        for (final File file : files) {
            if (file.isFile()) {
                uploadFile(ftpClient, file.getAbsolutePath(), targetDirectoryPath, nextLevelPrefix);
            } else {
                uploadDirectory(ftpClient, Paths.get(sourceDirectoryPath, file.getName()).toString(),
                        targetDirectoryPath + "/" + file.getName(), nextLevelPrefix);
            }
        }
    }
327288
static function copyDirectory($source, $target, $overwrite = true)
    {
        $scanResult = static::scanDirectory($source);
        if (!$scanResult) return false;
        if (!is_dir($target)) self::createDirectory($target);

        try {
            $sourceRealPath = realpath($source);
            foreach ($scanResult['files'] as $file) {
                $targetRealPath = realpath($target) . '/' . ltrim(substr($file, strlen($sourceRealPath)), '/');
                static::copyFile($file, $targetRealPath, $overwrite);
            }
            return true;
        } catch (\Throwable $throwable) {
            return false;
        }
    }
146467
def copyfile_and_gzip(self, source_path, target_path):
        
        # And then where we want to copy it to.
        target_dir = path.dirname(target_path)
        if not self.fs.exists(target_dir):
            try:
                self.fs.makedirs(target_dir)
            except OSError:
                pass

        # determine the mimetype of the file
        guess = mimetypes.guess_type(source_path)
        content_type = guess[0]
        encoding = guess[1]

        # If it isn't a file want to gzip...
        if content_type not in self.gzip_file_match:
            # just copy it to the target.
            logger.debug("Copying {}{} to {}{} because its filetype isn't on the whitelist".format(
                "osfs://",
                source_path,
                self.fs_name,
                target_path
            ))
            copy.copy_file("osfs:///", smart_text(source_path), self.fs, smart_text(target_path))

        # # if the file is already gzipped
        elif encoding == 'gzip':
            logger.debug("Copying {}{} to {}{} because it's already gzipped".format(
                "osfs://",
                source_path,
                self.fs_name,
                target_path
            ))
            copy.copy_file("osfs:///", smart_text(source_path), self.fs, smart_text(target_path))

        # If it is one we want to gzip...
        else:
            # ... let the world know ...
            logger.debug("Gzipping {}{} to {}{}".format(
                "osfs://",
                source_path,
                self.fs_name,
                target_path
            ))
            # Open up the source file from the OS
            with open(source_path, 'rb') as source_file:
                # Write GZIP data to an in-memory buffer
                data_buffer = six.BytesIO()
                kwargs = dict(
                    filename=path.basename(target_path),
                    mode='wb',
                    fileobj=data_buffer
                )
                if float(sys.version[:3]) >= 2.7:
                    kwargs['mtime'] = 0
                with gzip.GzipFile(**kwargs) as f:
                    f.write(six.binary_type(source_file.read()))

                # Write that buffer out to the filesystem
                with self.fs.open(smart_text(target_path), 'wb') as outfile:
                    outfile.write(data_buffer.getvalue())
                    outfile.close()
663727
public function copy(ClassCopyLogger $logger, string $src, string $dest)
    {
        $srcPath = $this->classFileNormalizer->normalizeToFile($src);
        $destPath = $this->classFileNormalizer->normalizeToFile($dest);

        return $this->copyFile($logger, $srcPath, $destPath);
    }
269999
public function copyTo($file, $target)
    {
        $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
        if ($this->enabled && file_exists($this->root . $file)) {
            try {
                touch($this->root . $file, filemtime($this->root . $file), time());
            } catch (\ErrorException $e) {
                // fallback in case the above failed due to incorrect ownership
                // see https://github.com/composer/composer/issues/4070
                touch($this->root . $file);
            }

            if ($this->io->isDebug()) {
                $this->io->writeError('Reading '.$this->root . $file.' from cache');
            }

            return copy($this->root . $file, $target);
        }

        return false;
    }
812553
protected function move($sourcePath, $targetPath)
    {
        if ($this->filesystem->has($targetPath)) {
            return false;
        }

        $stream = fopen($sourcePath, 'r+');
        if ($stream === null) {
            return false;
        }

        $success = $this->filesystem->writeStream($targetPath, $stream);

        if (fclose($stream) === false) {
            return false;
        }

        unlink($sourcePath);

        return $success;
    }
1142149
protected function symlink($target, $link, $logShort = false)
    {
        $fs = FileSystem::getFileSystem();

        // Convert target to relative path.
        $absolutePath = (new PhingFile($link))->getAbsolutePath();
        $link         = $absolutePath;

        if ($logShort) {
            $relativePath = str_replace(
                $this->getProject()->getBaseDir(),
                "", $absolutePath
            );
            $linkName     = basename($absolutePath);
        } else {
            $linkName = $link;
        }

        // @codingStandardsIgnoreLine: MULTISITE-17111
        $target = rtrim(
            $this->makePathRelative($target, dirname($link)),
            '/'
        );

        if (is_link($link) && @readlink($link) == $target) {
            $this->log('Link exists: '.$linkName, Project::MSG_INFO);

            return true;
        }

        if (file_exists($link) || is_link($link)) {
            if (!$this->getOverwrite()) {
                $this->log(
                    'Not overwriting existing link '.$link,
                    Project::MSG_ERR
                );

                return false;
            }

            if (is_link($link) || is_file($link)) {
                $fs->unlink($link);
                $this->log(
                    'Link removed: '.$linkName,
                    Project::MSG_INFO
                );
            } else {
                $fs->rmdir($link, true);
                $this->log(
                    'Directory removed: '.$linkName,
                    Project::MSG_INFO
                );
            }
        }

        $this->log('Linking: '.$linkName.' to '.$target, Project::MSG_INFO);

        return $fs->symlink($target, $link);

    }
491933
public function log($msg,$log_path = null)
    {
        $option = [
            'type' => 'File',
            'file_size' => 2097152,
            'time_format' => 'c',
        ];
        if ($log_path) {
            $option['path'] = WX_API_PATH.'/../../log/wx/';
        }else{
            $option['path'] = $log_path;
        }
        \think\Log::init($option);
        \think\Log::record($msg);
    }
181719
public function moveFile($origFilePath, $targetFilePath) {
		$this->copyFile($this->getBucket() . "/" . $origFilePath, $targetFilePath);
		$this->deleteFile($origFilePath);
	}
878455
protected function move(UploadFile $file, $targetPath)
    {
        $fileInfo = [
            'name' => pathinfo($targetPath, PATHINFO_BASENAME),
            'path' => $targetPath,
            'mime' => $file->getFileMime(),
            'size' => $file->getSize(),
        ];

        $file->moveTo($targetPath);

        if ( ! $file->getError()) {
            $this->uploadedFiles[] = $fileInfo;
        } else {
            $this->errors[] = $file->getError();
        }
    }