Skip to content

Commit

Permalink
Merge pull request #849 from catalyst/file-glob-rename
Browse files Browse the repository at this point in the history
Update file glob copy to work on single files
  • Loading branch information
keevan authored Nov 29, 2023
2 parents 679dfff + c73d8bc commit b8819bf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions classes/local/step/copy_file_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,26 @@ public function execute($input = null) {
}

// Attempt to copy the file to the destination.
// If $to is not a directory, then it should not glob anything and copy as-is.
if (!is_dir($to)) {
// If $to is not a directory and $from exists as a file, then it should not glob anything and copy as-is.
if (!is_dir($to) && file_exists($from)) {
$this->copy($from, $to);
return $input;
}

// Otherwise, it is probably multiple files, and should be globbed.
// Otherwise, it is probably multiple files or a file to be renamed, and should be globbed.
$files = glob($from);
if (empty($files)) {
return $input;
}

$this->log('Copying ' . count($files) . ' files');
// Copy all files direct to the endpoint specified, either a direct target or in directory.
$targetdir = is_dir($to);
foreach ($files as $file) {
if (!is_dir($file) && is_readable($file)) {
$dest = realpath($to . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($file);
$dest = $targetdir
? realpath($to . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($file)
: $to;
$this->copy($file, $dest);
}
}
Expand Down

0 comments on commit b8819bf

Please sign in to comment.