async function handleCvdUpdate()

in cloudrun-malware-scanner/server.ts [133:167]


async function handleCvdUpdate(config: Config): Promise<{
  status: string;
  updated: boolean;
}> {
  try {
    logger.info('Starting CVD Mirror update');
    const result = await execFilePromise('./updateCvdMirror.sh', [
      config.ClamCvdMirrorBucket,
    ]);
    logger.info('CVD Mirror update check complete. output:\n' + result.stdout);
    // look for updated versions in output by looking for
    // "updated (version: " from freshclam output.
    const newVersions = result.stdout
      .split('\n')
      // Look for lines beginning with Downloaded
      .filter((line) => line.indexOf('Downloaded') >= 0);
    for (const version of newVersions) {
      logger.info(`CVD Mirror updated: ${version}`);
    }
    const isUpdated = newVersions.length > 0;
    metrics.writeCvdMirrorUpdated(true, isUpdated);
    return {
      status: 'CvdUpdateComplete',
      updated: isUpdated,
    };
  } catch (e) {
    const err = e as ExecFileException;
    logger.error(
      {err},
      `Failure when running ./updateCvdMirror.sh: ${err.message}\nstdout: ${err.stdout}\nstderr: \n${err.stderr}`,
    );
    metrics.writeCvdMirrorUpdated(false, false);
    throw err as Error;
  }
}