<?php
// Removes only this slice's copied source and generated runtime, after sealed source proof.
if(__DIR__!=='/tmp/cdx-store-activity-crud4-20261011'||is_link(__DIR__)||!is_file(__DIR__.'/private/resource-proof.json')||!is_file(__DIR__.'/private/cleanup.json')||is_file(__DIR__.'/private/auth.json'))throw new RuntimeException('Exact own resource cleanup prerequisites');
$lock=json_decode(file_get_contents(__DIR__.'/source-lock.json'),true);$actual=[];$iter=new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__.'/source/application',FilesystemIterator::SKIP_DOTS));foreach($iter as $f){if($f->isLink())throw new RuntimeException('Source symlink');if($f->isFile())$actual[substr($f->getPathname(),strlen(__DIR__.'/source/application/'))]=hash_file('sha256',$f->getPathname());}ksort($actual);ksort($lock);if($actual!==$lock||count($actual)!==959)throw new RuntimeException('Copied source only');$removed=[];$erase=static function($dir)use(&$erase,&$removed){if(is_link($dir))throw new RuntimeException('No symlink cleanup');if(!is_dir($dir))return;foreach(scandir($dir)as $n){if($n==='.'||$n==='..')continue;$f=$dir.'/'.$n;if(is_link($f))throw new RuntimeException('No symlink cleanup');if(is_dir($f))$erase($f);else{$removed[]=['path'=>substr($f,strlen(__DIR__)+1),'sha256'=>hash_file('sha256',$f)];unlink($f);}}rmdir($dir);};$erase(__DIR__.'/source');$erase(__DIR__.'/runtime');if(is_dir(__DIR__.'/cache'))rmdir(__DIR__.'/cache');$r=['removed_own_copied_source_files'=>959,'removed_files'=>$removed,'source_mapping_sha256'=>hash_file('sha256',__DIR__.'/source-lock.json'),'source_recoverable_from_existing_APP959_original'=>true,'no_auth_copy'=>!is_file(__DIR__.'/private/auth.json'),'DB'=>0,'HTTP'=>0];$f=__DIR__.'/private/cleanup-source.json';$h=fopen($f,'xb');fwrite($h,json_encode($r,JSON_PRETTY_PRINT));fclose($h);chmod($f,0600);echo json_encode(['own_source_removed'=>959,'own_runtime_removed'=>true,'DB'=>0]),"\n";
