From 20a793c5ba1d7835db68c5a48196c389d5d823d3 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 5 Apr 2023 18:38:41 +0200 Subject: [PATCH] wip #5844 @1 --- src/Files/Files.php | 19 +++++++++++++++++++ src/Files/VirtualDirectory.php | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Files/Files.php b/src/Files/Files.php index 5b487d4..dd93bee 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -390,4 +390,23 @@ class Files return $res; } + /** + * @param $search string + * @param $replace string + * @param $filenames string|string[] + * @return void + */ + public static function str_replace($search, $replace, $filenames) + { + if (!is_array($filenames)) { + $filenames = [$filenames]; + } + foreach ($filenames as $filename) { + if (!file_exists($filename)) { + continue; + } + file_put_contents($filename, str_replace($search, $replace, file_get_contents($filename))); + } + } + } \ No newline at end of file diff --git a/src/Files/VirtualDirectory.php b/src/Files/VirtualDirectory.php index 3a40b64..e3d5c0a 100644 --- a/src/Files/VirtualDirectory.php +++ b/src/Files/VirtualDirectory.php @@ -33,6 +33,9 @@ class VirtualDirectory return $this; } if ($prepend) { + if (isset($this->_copy[$realto])) { + return $this; + } $this->_copy = array_merge([$realto => $from], $this->_copy); } else { $this->_copy[$realto] = $from; @@ -84,7 +87,7 @@ class VirtualDirectory throw new \Exception(sprintf('Failed to copy %s to %s. Source doesn\'t exist', $from, $to)); } - if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) > filemtime($to)) { + if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) !== filemtime($to)) { try { `cp -p $from $to`; } catch (\Exception $e) { -- 2.39.5