<?php
declare(strict_types=1);$dir=__DIR__.'/private/cache';$out=__DIR__.'/private/cache-cleanup.json';if(is_file($out)||is_link($dir)||!is_dir($dir))throw new RuntimeException('Exact own cache directory');$files=[];foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir,FilesystemIterator::SKIP_DOTS)) as $p){if($p->isLink()||!$p->isFile()||strpos($p->getPathname(),$dir.'/')!==0||!preg_match('/\/[a-f0-9]{2}\/[a-f0-9]{30}\.php$/D',$p->getPathname()))throw new RuntimeException('Unknown own cache target');$files[]=['path'=>$p->getPathname(),'bytes'=>$p->getSize(),'sha256'=>hash_file('sha256',$p->getPathname())];}foreach($files as $f){if(!unlink($f['path']))throw new RuntimeException('Own cache removal failed');}file_put_contents($out,json_encode(['own_cache_files_removed'=>$files,'shared_cache_touched'=>false,'HTTP'=>0,'DML'=>0,'at'=>date('c')],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));chmod($out,0600);echo json_encode(['own_cache_files_removed'=>count($files),'shared_cache_touched'=>false]),"\n";
