<?php
declare(strict_types=1);$root=__DIR__.'/source';$pins=json_decode(file_get_contents(__DIR__.'/source-frozen-sha.json'),true)['files'];$file=__DIR__.'/private/source-sidecars.json';if(file_exists($file))throw new RuntimeException('Source extra inventory once');$extra=[];foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root,FilesystemIterator::SKIP_DOTS)) as $p)if($p->isFile()){$n=substr($p->getPathname(),strlen($root)+1);if(isset($pins[$n]))continue;$bytes=file_get_contents($p->getPathname());if(strpos(basename($n),'._')!==0||bin2hex(substr($bytes,0,4))!=='00051607')throw new RuntimeException('Unknown executable/source extra');$extra[]=['path'=>$n,'sha256'=>hash('sha256',$bytes),'bytes'=>strlen($bytes),'magic'=>'00051607'];}file_put_contents($file,json_encode(['pinned_business_source'=>count($pins),'extra_files'=>$extra,'extra_kind'=>'Mac tar AppleDouble metadata; all basename._ and magic00051607; none allowed in actual included pin','actual_regular_file_count'=>count($pins)+count($extra)],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));chmod($file,0600);echo json_encode(['pinned_business_source'=>count($pins),'metadata_sidecars'=>count($extra),'all_AppleDouble'=>true]),"\n";
