From 13b76ed819d885397af1fc258a3daee803be7997 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Fri, 27 Sep 2024 12:37:57 +0200 Subject: [PATCH] add TimestampPattern --- src/Helper.php | 41 ++++++++++---------- src/Pattern/TimestampPattern.php | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 src/Pattern/TimestampPattern.php diff --git a/src/Helper.php b/src/Helper.php index 7383ba0..94622bb 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -19,30 +19,29 @@ class Helper * @param string $src * @param string $dst */ - static function copyDirectory( - string $src, - string $dst - ): void { + static function copyDirectory(string $src, string $dst): void + { + if (is_link($src) || is_link($dst)) { + return; + } + $dir = opendir($src); - mkdir($dst, 0777, true); + mkdir($dst, recursive: true); while (($file = readdir($dir)) !== false) { - if ( - $file === static::CURRENT_DIRECTORY - || $file === static::PARENT_DIRECTORY - ) { + if ($file === static::CURRENT_DIRECTORY || $file === static::PARENT_DIRECTORY) { continue; } + $newSrc = $src . DIRECTORY_SEPARATOR . $file; + $newDst = $dst . DIRECTORY_SEPARATOR . $file; + if (is_dir($src . DIRECTORY_SEPARATOR . $file)) { - static::copyDirectory( - $src . DIRECTORY_SEPARATOR . $file, - $dst . DIRECTORY_SEPARATOR . $file - ); + static::copyDirectory($newSrc, $newDst); } else { - copy( - $src . DIRECTORY_SEPARATOR . $file, - $dst . DIRECTORY_SEPARATOR . $file - ); + if (is_link($newSrc) || is_link($newDst)) { + continue; + } + copy($newSrc, $newDst); } } closedir($dir); @@ -53,12 +52,16 @@ static function copyDirectory( * * @param string $path */ - static function removeDirectory(string $path) + static function removeDirectory(string $path): void { if (substr($path, -1) !== DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } + if (!is_dir($path) || is_link($path)) { + return; + } + $directory = dir($path); while ($file = $directory->read()) { if (in_array($file, [static::CURRENT_DIRECTORY, static::PARENT_DIRECTORY])) { @@ -66,7 +69,7 @@ static function removeDirectory(string $path) } $filePath = $path . $file; - if (is_dir($filePath)) { + if (is_dir($filePath) && !is_link($filePath)) { static::removeDirectory($filePath); } else { unlink($filePath); diff --git a/src/Pattern/TimestampPattern.php b/src/Pattern/TimestampPattern.php new file mode 100644 index 0000000..58390e2 --- /dev/null +++ b/src/Pattern/TimestampPattern.php @@ -0,0 +1,64 @@ +getTimestamp(); + return $time > $this->minTimestamp || ($time === -1 && !$this->removeUnknownChunks); + } + + /** + * @return int + */ + public function getMinTimestamp(): int + { + return $this->minTimestamp; + } + + /** + * @param int $minTimestamp + * @return $this + */ + public function setMinTimestamp(int $minTimestamp): TimestampPattern + { + $this->minTimestamp = $minTimestamp; + return $this; + } + + /** + * @return bool + */ + public function getRemoveUnknownChunks(): bool + { + return $this->removeUnknownChunks; + } + + /** + * @param bool $removeUnknownChunks + * @return $this + */ + public function setRemoveUnknownChunks(bool $removeUnknownChunks): TimestampPattern + { + $this->removeUnknownChunks = $removeUnknownChunks; + return $this; + } +}