From 433e169f06357eb7c9b43464b1a08624dcdf48bc Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sun, 6 Oct 2019 15:54:06 +0100 Subject: [PATCH] Lock off file from http, git diff -> MD5 to rescan --- processes/system.php | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/processes/system.php b/processes/system.php index f028d4d..7a044aa 100644 --- a/processes/system.php +++ b/processes/system.php @@ -1,12 +1,45 @@ ", "", $prevIndexData); + $prevIndexData = unserialize($prevIndexData); + // Set timestamp back to epoch to force a re-index next time + $prevIndexData['timestamps']['indexed'] = 0; + file_put_contents(dirname(__FILE__)."/../data/index.php", ""); + } + } +} + +// Run continuously while(true) { - $gitData = shell_exec("cd .. && { git diff --name-only --staged ; git ls-files --other --modified --exclude-standard ;} | sort | uniq"); - $diffLines = explode("\n", $gitData); - $output = ["paths" => array_filter($diffLines)]; - // Store the serialized array in PHP comment block for pick up - file_put_contents(dirname(__FILE__)."/../data/git-diff.php", ""); - sleep(2); + // Get git diff output as a string and MD5 it as a checksum + $thisMD5 = shell_exec("cd .. && git diff | md5sum"); + // If we have a previous checksum value and the current is different to it + if (isset($prevMD5) && $thisMD5 !== $prevMD5) { + // Set timestamp of last index to 0 to force a re-index next time we index + requireReIndexNextTime(); + // Get a list of all that's changed, into an array (filtered to remove false entries) + $gitData = shell_exec("cd .. && { git diff --name-only --staged ; git ls-files --other --modified --exclude-standard ;} | sort | uniq"); + $diffLines = explode("\n", $gitData); + $output = ["paths" => array_filter($diffLines)]; + // Store the serialized array in PHP comment block for pick up + file_put_contents(dirname(__FILE__)."/../data/git-diff.php", ""); + // Set prev MD5 to this one, ready for next time, sleep for 2 secs before loop starts again + $prevMD5 = $thisMD5; + sleep(2); + } } ?>