[Libosinfo] [osinfo-db-tools PATCH 3/3] util: Do not assume --root argument ends with '/'

Fabiano Fidêncio fidencio at redhat.com
Thu Apr 4 15:47:44 UTC 2019


Current situation is that whenever --root is passed its argument has to
finish with a '/' otherwise the system, local, or user dir would be
concatened to it as "%s%s".

Instead of building the filename by ourselves, let's just rely on
g_build_filename().

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 tools/osinfo-db-util.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/osinfo-db-util.c b/tools/osinfo-db-util.c
index 177c6f1..1030b06 100644
--- a/tools/osinfo-db-util.c
+++ b/tools/osinfo-db-util.c
@@ -39,7 +39,7 @@ GFile *osinfo_db_get_system_path(const gchar *root)
     if (!path)
         path = DATA_DIR "/osinfo";
 
-    dbdir = g_strdup_printf("%s%s", root, path);
+    dbdir = g_build_filename(root, path, NULL);
     file = g_file_new_for_path(dbdir);
     g_free(dbdir);
     return file;
@@ -54,7 +54,7 @@ GFile *osinfo_db_get_local_path(const gchar *root)
     if (!path)
         path = SYSCONFDIR "/osinfo";
 
-    dbdir = g_strdup_printf("%s%s", root, path);
+    dbdir = g_build_filename(root, path, NULL);
     file = g_file_new_for_path(dbdir);
     g_free(dbdir);
     return file;
@@ -69,9 +69,9 @@ GFile *osinfo_db_get_user_path(const gchar *root)
     const gchar *configdir = g_get_user_config_dir();
 
     if (path) {
-        dbdir = g_strdup_printf("%s%s", root, path);
+        dbdir = g_build_filename(root, path, NULL);
     } else {
-        dbdir = g_strdup_printf("%s%s/osinfo", root, configdir);
+        dbdir = g_build_filename(root, configdir, "osinfo", NULL);
     }
     file = g_file_new_for_path(dbdir);
     g_free(dbdir);
@@ -85,7 +85,7 @@ GFile *osinfo_db_get_custom_path(const gchar *dir,
     GFile *file;
     gchar *dbdir;
 
-    dbdir = g_strdup_printf("%s%s", root, dir);
+    dbdir = g_build_filename(root, dir, NULL);
     file = g_file_new_for_path(dbdir);
     g_free(dbdir);
     return file;
-- 
2.21.0




More information about the Libosinfo mailing list