Skip to content

Commit

Permalink
Cleanup the zkg scratch directory while refreshing packages
Browse files Browse the repository at this point in the history
  • Loading branch information
timwoj committed Feb 1, 2025
1 parent 1d72792 commit 8f8fc99
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cronjob/bro-pkg-web-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function required_exec($cmd, $timeout=30) {
// Get a list of all bro packages
$pkgarray = required_exec("$zkg_exec list all --nodesc");

$zkg_scratch_dir = required_exec("$zkg_exec config state_dir")[0];
$zkg_scratch_dir .= "/scratch";

$pkgcount = count($pkgarray);
if ($pkgcount > 0) {
echo "Processing $pkgcount packages\n\n";
Expand Down Expand Up @@ -184,14 +187,15 @@ function required_exec($cmd, $timeout=30) {
curl_close($ch);
}

$parts = explode("/", $pkgs[$pkg]['url']);
$pkgshort = end($parts);

// Get all versions of metadatas for the package
if (property_exists($pkgjson->$pkg, 'metadata')) {
$versions = array_keys(get_object_vars($pkgjson->$pkg->metadata));

// Clone the code from github to run bro-package-check
// on each metadata branch version
$parts = explode("/", $pkgs[$pkg]['url']);
$pkgshort = end($parts);
$tempdir = mkTempDir();
$pkgdir = $tempdir . '/' . $pkgshort;
$chdirok = chdir($tempdir);
Expand Down Expand Up @@ -256,6 +260,9 @@ function required_exec($cmd, $timeout=30) {
deleteDir($tempdir);
}
}

// Delete the scratch directory for this package so the disk doesn't fill up
deleteDir("$zkg_scratch_dir/$pkgshort");
}
if ($pkgcount > 0) {
echo "Done!\n";
Expand Down

0 comments on commit 8f8fc99

Please sign in to comment.