/** * Will return an array with the newest exported versions of each component. */ function get_exported_components(){ $c = []; $dir = ROOT_PDIR . '../exports/components'; if(!is_dir($dir)){ // Doesn't exist? Don't even try opening it. return $c; } $dh = opendir($dir); if(!$dh){ // Easy enough, just return a blank array! return $c; } while(($file = readdir($dh)) !== false){ if($file{0} == '.') continue; if(is_dir($dir . '/' . $file)) continue; // Get the extension type. if(preg_match('/\.tgz$/', $file)){ $signed = false; $fbase = substr($file, 0, -4); } elseif(preg_match('/\.tgz\.asc$/', $file)){ $signed = true; $fbase = substr($file, 0, -8); } else{ continue; } // Split up the name and the version. // This is a little touchy because a dash in the package name is perfectly valid. // instead, grab the last dash in the string. // Additionally, versions such as: // name-1.2.3 // name-blah-1.2.3 // name-blah-1.2.3-4 // must all be supported. preg_match('/^([a-z\.\-]*)-(r[0-9]|[0-9][0-9abrc\.\-]*)(~.*)?$/', $fbase, $fileparts); switch(sizeof($fileparts)){ case 3: $n = $fileparts[1]; $v = $fileparts[2]; break; case 4: $n = $fileparts[1]; $v = $fileparts[2] . $fileparts[3]; break; default: CLI::PrintWarning('Unsupported file version string: [' . $fbase . '], please submit this.'); continue; } //$dash = strrpos($fbase, '-'); //$n = substr($fbase, 0, $dash); //$v = substr($fbase, ($dash+1)); // instead, I need to look for a dash followed by a number. This should indicate the version number. //preg_match('/^(.*)\-([0-9]+.*)$/', $fbase, $matches); //$n = $matches[1]; //$v = $matches[2]; // Tack it on. if(!isset($c[$n])){ $c[$n] = ['version' => $v, 'signed' => $signed, 'filename' => $dir . '/' . $file]; } else{ switch(Core::VersionCompare($c[$n]['version'], $v)){ case -1: // Existing older, overwrite! $c[$n] = ['version' => $v, 'signed' => $signed, 'filename' => $dir . '/' . $file]; break; case 0: // Same, check the signed status. if($signed) $c[$n] = ['version' => $v, 'signed' => $signed, 'filename' => $dir . '/' . $file]; break; default: // Do nothing, current is at a higher version. } } } closedir($dh); return $c; } // function get_exported_components()