<?php
namespace Cubist\Util\Files;
+
+use Cubist\Util\CommandLine;
+
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`));
}
/**