]> xenbits.xensource.com Git - libvirt.git/commitdiff
testQemuGetLatestCapsForArch: Rewrite using testQemuGetLatestCaps
authorPeter Krempa <pkrempa@redhat.com>
Tue, 7 Mar 2023 15:01:35 +0000 (16:01 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Apr 2023 07:19:06 +0000 (09:19 +0200)
Fetch the full hash of 'latest' files and just return the correct one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/testutilsqemu.c

index 946f985d58c7dc88873244b46f1c5f6eb12aed03..917cdc02a377bdab32a2377953435e7b3fdfe741 100644 (file)
@@ -731,54 +731,22 @@ char *
 testQemuGetLatestCapsForArch(const char *arch,
                              const char *suffix)
 {
-    struct dirent *ent;
-    g_autoptr(DIR) dir = NULL;
-    int rc;
-    g_autofree char *fullsuffix = NULL;
-    unsigned long long maxver = 0;
-    unsigned long long ver;
-    g_autofree char *maxname = NULL;
-
-    fullsuffix = g_strdup_printf("%s.%s", arch, suffix);
-
-    if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0)
-        return NULL;
-
-    while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
-        g_autofree char *tmp = NULL;
-
-        tmp = g_strdup(STRSKIP(ent->d_name, "caps_"));
+    g_autoptr(GHashTable) caps = testQemuGetLatestCaps();
+    struct testQemuCapsFile *f;
 
-        if (!tmp)
-            continue;
-
-        if (!virStringStripSuffix(tmp, fullsuffix))
-            continue;
-
-        if (virStringParseVersion(&ver, tmp, false) < 0) {
-            VIR_TEST_DEBUG("skipping caps file '%s'", ent->d_name);
-            continue;
-        }
-
-        if (ver > maxver) {
-            g_free(maxname);
-            maxname = g_strdup(ent->d_name);
-            maxver = ver;
-        }
-    }
-
-    if (rc < 0)
-        return NULL;
-
-    if (!maxname) {
+    if (!(f = g_hash_table_lookup(caps, arch))) {
         VIR_TEST_VERBOSE("failed to find capabilities for '%s' in '%s'",
                          arch, TEST_QEMU_CAPS_PATH);
         return NULL;
     }
 
-    return g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
-}
+    if (STRNEQ(suffix, "xml")) {
+        ignore_value(virStringStripSuffix(f->path, "xml"));
+        return g_strdup_printf("%s%s", f->path, suffix);
+    }
 
+    return g_steal_pointer(&f->path);
+}
 
 GHashTable *
 testQemuGetLatestCaps(void)