<?php
declare(strict_types=1);
// Only generated AppleDouble files inside this batch's two exact private overlays.
$base=$argv[1]??'';$allow=['/tmp/cdx-store-menu7-B-PDEqef','/tmp/cdx-store-menu7-C-Vy4WDq'];if(!in_array($base,$allow,true)){exit(78);}
$source=$base.'/source/application';$items=[];
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source,FilesystemIterator::SKIP_DOTS)) as $f){
    if($f->isFile()&&strpos($f->getFilename(),'._')===0){$p=$f->getPathname();$h=fopen($p,'rb');$magic=fread($h,4);fclose($h);if($magic!=="\0\5\26\7"){throw new RuntimeException('Not generated AppleDouble; refuse');}$items[]=$p;}
}
foreach($items as $p){$q=$base.'/appledouble-quarantine/'.substr($p,strlen($source)+1);if(!is_dir(dirname($q))){mkdir(dirname($q),0700,true);}if(file_exists($q)||!rename($p,$q)){throw new RuntimeException('Recoverable quarantine failed');}}
echo json_encode(['generated_files_moved'=>count($items),'source_bytes_changed'=>false,'recoverable'=>true,'database_operations'=>0]),PHP_EOL;
