LCOV - code coverage report
Current view: top level - pkg/apps - appstream.js Coverage Total Hit
Test: cockpit Lines: 96.6 % 29 28
Test Date: 2026-07-02 14:11:36

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2017 Red Hat, Inc.
       3              :  * SPDX-License-Identifier: LGPL-2.1-or-later
       4              :  */
       5              : 
       6            6 : import cockpit from "cockpit";
       7              : import * as python from "python.js";
       8              : import inotify_py from "inotify.py";
       9              : 
      10              : import { debug } from "./utils";
      11              : import watch_appstream_py from "./watch-appstream.py";
      12              : 
      13            6 : let metainfo_db = null;
      14              : 
      15            6 : export function get_metainfo_db() {
      16            6 :     if (!metainfo_db) {
      17            6 :         metainfo_db = cockpit.event_target({
      18            6 :             ready: false,
      19            6 :             components: [],
      20            6 :             origin_files: []
      21            6 :         });
      22              : 
      23            6 :         let buf = "";
      24            6 :         python.spawn([inotify_py, watch_appstream_py], [],
      25            1 :                      { environ: ["LANGUAGE=" + (cockpit.language || "en")] })
      26            6 :                 .stream(function (data) {
      27            6 :                     buf += data;
      28            6 :                     const lines = buf.split("\n");
      29            6 :                     buf = lines[lines.length - 1];
      30            6 :                     if (lines.length >= 2) {
      31            6 :                         const metadata = JSON.parse(lines[lines.length - 2]);
      32            6 :                         metainfo_db.components = metadata.components;
      33            6 :                         metainfo_db.origin_files = metadata.origin_files;
      34            6 :                         metainfo_db.ready = true;
      35            6 :                         metainfo_db.dispatchEvent("changed");
      36            6 :                         debug("read metainfo_db:", metainfo_db);
      37            6 :                     }
      38            6 :                 })
      39            0 :                 .catch(error => console.warn("watch-appstream.py failed:", error));
      40            6 :     }
      41              : 
      42            6 :     return metainfo_db;
      43            6 : }
        

Generated by: LCOV version 2.0-1