From ed6df29ebba7f648a2d5f8a5b9cef6994ac7b4a3 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 10 Feb 2023 14:32:22 +0100 Subject: [PATCH] wip #5721 @0.5 --- src/Files/VirtualDirectory.php | 2 +- src/Gzip.php | 151 +++++++++++++++++---------------- 2 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/Files/VirtualDirectory.php b/src/Files/VirtualDirectory.php index 013ce01..3a40b64 100644 --- a/src/Files/VirtualDirectory.php +++ b/src/Files/VirtualDirectory.php @@ -86,7 +86,7 @@ class VirtualDirectory if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) > filemtime($to)) { try { - copy($from, $to); + `cp -p $from $to`; } catch (\Exception $e) { throw new \Exception(sprintf('Failed to copy %s to %s', $from, $to)); } diff --git a/src/Gzip.php b/src/Gzip.php index 290ebc3..65784b5 100644 --- a/src/Gzip.php +++ b/src/Gzip.php @@ -5,89 +5,90 @@ use Cubist\Util\Files\Files; class Gzip { - public static function compressIfNotCompressed($filename) - { - if (file_exists($filename) && file_exists($filename . '.gz')) { - if (filemtime($filename) >= filemtime($filename . '.gz')) { - unlink($filename . '.gz'); - } else { - unlink($filename); - } - } - if (file_exists($filename) && !file_exists($filename . '.gz')) { - `gzip $filename`; - } - } + public static function compressIfNotCompressed($filename) + { + if (file_exists($filename) && file_exists($filename . '.gz')) { + if (filemtime($filename) >= filemtime($filename . '.gz')) { + unlink($filename . '.gz'); + } else { + unlink($filename); + } + } - public static function unlink($filename) - { - if (file_exists($filename)) { - unlink($filename); - } - if (file_exists($filename . '.gz')) { - unlink($filename . '.gz'); - } - } + if (file_exists($filename) && !file_exists($filename . '.gz')) { + `gzip $filename`; + } + } - public static function file_exists($filename) - { - return file_exists($filename . '.gz') || file_exists($filename); - } + public static function unlink($filename) + { + if (file_exists($filename)) { + unlink($filename); + } + if (file_exists($filename . '.gz')) { + unlink($filename . '.gz'); + } + } - public static function filemtime($filename) - { - if (file_exists($filename . '.gz')) { - return filemtime($filename . '.gz'); - } else if (file_exists($filename)) { - return filemtime($filename); - } else { - return false; - } - } + public static function file_exists($filename) + { + return file_exists($filename . '.gz') || file_exists($filename); + } - public static function file_get_contents($filename) - { - self::_filename($filename); - $fp = self::_fopen($filename, 'rb'); - $res = stream_get_contents($fp); - fclose($fp); - return $res; - } + public static function filemtime($filename) + { + if (file_exists($filename . '.gz')) { + return filemtime($filename . '.gz'); + } else if (file_exists($filename)) { + return filemtime($filename); + } else { + return false; + } + } - public static function file_put_contents($filename, $data, $compression = 7, $mode = 'w') - { - self::_filename($filename, true); - $fp = self::_fopen($filename, $mode, $compression); - $res = fwrite($fp, $data); - fclose($fp); - return $res; - } + public static function file_get_contents($filename) + { + self::_filename($filename); + $fp = self::fopen($filename); + $res = stream_get_contents($fp); + fclose($fp); + return $res; + } - protected static function _fopen($filename, $mode, $compression = 7) - { - $protocol = self::_protocol($filename); - if ($protocol == 'compress.zlib://') { - $mode .= $compression; - } - return fopen($protocol . $filename, $mode); - } + public static function file_put_contents($filename, $data, $compression = 7, $mode = 'w') + { + self::_filename($filename, true); + $fp = self::fopen($filename, $mode, $compression); + $res = fwrite($fp, $data); + fclose($fp); + return $res; + } - protected static function _protocol($filename) - { - if (Files::getExtension($filename) == 'gz') { - $protocol = 'compress.zlib://'; - } else { - $protocol = ''; - } - return $protocol; - } + protected static function fopen($filename, $mode='rb', $compression = 7) + { + $protocol = self::_protocol($filename); + if ($protocol == 'compress.zlib://') { + $mode .= $compression; + } + return fopen($protocol . $filename, $mode); + } - protected static function _filename(&$filename, $forceGzip = false) - { - if ($forceGzip || (!file_exists($filename) && file_exists($filename . '.gz'))) { - $filename .= '.gz'; - } - } + protected static function _protocol($filename) + { + if (Files::getExtension($filename) == 'gz') { + $protocol = 'compress.zlib://'; + } else { + $protocol = ''; + } + return $protocol; + } + + protected static function _filename(&$filename, $forceGzip = false) + { + if ($forceGzip || (!file_exists($filename) && file_exists($filename . '.gz'))) { + $filename .= '.gz'; + } + } } -- 2.39.5