Match worker fingerprint for stale detection

This commit is contained in:
hbrain 2026-05-28 18:00:50 +02:00
parent 47c15124d9
commit cf6830e803

29
new.php
View file

@ -136,15 +136,26 @@ function unique_input_dir($base, $slug){
} }
} }
function input_dir_signature($dir){ function input_dir_signature($dir){
$entries = []; $script = <<<'PY'
foreach (scandir($dir) ?: [] as $file) { import hashlib, json, os, sys
if ($file === '.' || $file === '..' || in_array($file, ['.movmaker-state.json','.movmaker-enabled','.movmaker-preview','.mvlog-hidden'], true)) continue; root = sys.argv[1]
if ($file === '.movmaker-lock') continue; entries = []
$path = $dir . '/' . $file; for dirpath, dirnames, filenames in os.walk(root):
if (is_file($path)) $entries[] = [$file, filesize($path), filemtime($path)]; dirnames[:] = [d for d in dirnames if d != '.movmaker-lock']
} for name in filenames:
sort($entries); if name in {'.movmaker-state.json', '.movmaker-enabled', '.movmaker-preview', '.mvlog-hidden'}:
return hash('sha256', json_encode($entries, JSON_UNESCAPED_UNICODE)); continue
path = os.path.join(dirpath, name)
rel = os.path.relpath(path, root)
st = os.stat(path)
mtime_ns = getattr(st, 'st_mtime_ns', int(st.st_mtime * 1_000_000_000))
entries.append([rel, st.st_size, mtime_ns])
entries.sort()
print(hashlib.sha256(json.dumps(entries, ensure_ascii=False, separators=(',', ':')).encode('utf-8')).hexdigest())
PY;
$cmd = 'python3 -c ' . escapeshellarg($script) . ' ' . escapeshellarg($dir);
$output = trim(shell_exec($cmd) ?? '');
return $output !== '' ? $output : '';
} }
function input_dir_info($dir){ function input_dir_info($dir){
$data = read_data($dir); $data = read_data($dir);