[PATCH 4/4] loader: treat zero length file as an entity blackout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the user creates a zero length XML file, this should override
the equivalent filename in an earlier directory, but should not
itself be loaded. This functions as a blackout, allowing the
user to hide content provided by the system.
---
 osinfo/osinfo_loader.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index a5e26ad..10b9fff 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1859,7 +1859,7 @@ osinfo_loader_process_file_reg_pci(OsinfoLoader *loader,
                                        err);
 }
 
-static void
+static int
 osinfo_loader_process_file_reg_xml(OsinfoLoader *loader,
                                    GFile *base,
                                    GFile *file,
@@ -1871,7 +1871,10 @@ osinfo_loader_process_file_reg_xml(OsinfoLoader *loader,
 
     g_file_load_contents(file, NULL, &xml, &xmlLen, NULL, err);
     if (error_is_set(err))
-        return;
+        return -1;
+
+    if (xmlLen == 0)
+        return 0; /* zero length file treated as a black-list */
 
     relpath = g_file_get_relative_path(base, file);
     if (relpath == NULL) {
@@ -1887,6 +1890,7 @@ osinfo_loader_process_file_reg_xml(OsinfoLoader *loader,
     g_free(uri);
     g_free(xml);
     g_free(relpath);
+    return 1;
 }
 
 
@@ -2130,19 +2134,28 @@ static void osinfo_loader_process_list(OsinfoLoader *loader,
     while (g_hash_table_iter_next(&iter, &key, &value)) {
         OsinfoLoaderEntityFiles *files = value;
         GList *tmpl;
+        gboolean blackout = FALSE;
         if (files->master) {
-            osinfo_loader_process_file_reg_xml(loader,
-                                               g_object_get_data(G_OBJECT(files->master), "base"),
-                                               files->master, &lerr);
+            int ret = osinfo_loader_process_file_reg_xml(loader,
+                                                         g_object_get_data(G_OBJECT(files->master), "base"),
+                                                         files->master, &lerr);
             if (lerr) {
                 g_propagate_error(err, lerr);
                 break;
             }
+            if (ret == 0) {
+                blackout = TRUE;
+            }
         }
 
         tmpl = files->extensions;
         while (tmpl) {
             GFile *file = tmpl->data;
+            if (blackout) {
+                gchar *path = g_file_get_path(file);
+                g_warning("Entity master file blackout but extension %s found",
+                          path);
+            }
             osinfo_loader_process_file_reg_xml(loader,
                                                g_object_get_data(G_OBJECT(file), "base"),
                                                file,
-- 
2.4.3

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux