From c73d8bc4cd3c1122328d5df126e394d6c15788b6 Mon Sep 17 00:00:00 2001 From: Peter Burnett Date: Wed, 29 Nov 2023 09:54:54 +1000 Subject: [PATCH] Update file glob copy to work on single files --- classes/local/step/copy_file_trait.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/classes/local/step/copy_file_trait.php b/classes/local/step/copy_file_trait.php index 9d3ebbd5..30a081c5 100644 --- a/classes/local/step/copy_file_trait.php +++ b/classes/local/step/copy_file_trait.php @@ -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); } }