]> _ Git - cubist_util.git/commitdiff
wait #4209 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 1 Sep 2022 16:15:46 +0000 (18:15 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 1 Sep 2022 16:15:46 +0000 (18:15 +0200)
src/Files/Files.php

index 87a0f5c516752ffdd0a575449b6e8676ce535078..616ece063064f3067ec1124102666ca2c06a6659 100644 (file)
@@ -1,6 +1,9 @@
 <?php
 
 namespace Cubist\Util\Files;
+
+use Cubist\Util\CommandLine;
+
 class Files
 {
 
@@ -278,31 +281,23 @@ class Files
         return tempnam($dir, $prefix);
     }
 
-    public static function dirmtime($dir, $recursive = false)
+    public static function dirmtime($dir, $recursive = false, $extensions = [])
     {
-        $time = filemtime($dir);
-        $files = self::getDirectoryIterator($dir, $recursive);
-        foreach ($files as $f) {
-            $time = max($time, $f->getMTime());
+        $cmd = 'find ' . $dir . ' ';
+        if (!$recursive) {
+            $cmd .= '-maxdepth 1 -mindepth 1 ';
         }
-        return $time;
-    }
-
-    public static function checkHashDir($dir)
-    {
-        $nb = 0;
-        $time = 0;
-        $size = 0;
-
-        $files = self::getDirectoryIterator($dir, true);
-
-        foreach ($files as $f) {
-            $time = max($time, $f->getMTime());
-            $nb++;
-            $size += $f->getSize();
+        $cmd .= '-type f ';
+        if (count($extensions)) {
+            $cmd .= '\( ';
+            $exts = [];
+            foreach ($extensions as $extension) {
+                $exts[] = '-name "*.' . $extension . '"';
+            }
+            $cmd .= implode(' -o ', $exts) . ' \) ';
         }
-
-        return hash('sha256', $dir . '$$' . $nb . '//' . $size . '|||' . $time);
+        $cmd .= '-type f -printf "%T@ %p\n" | sort -n | cut -d\' \' -f 2- | tail -n 1';
+        return filemtime(trim(`$cmd`));
     }
 
     /**