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

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

 



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@xxxxxxxxxx>
---
 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

_______________________________________________
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