[PATCH db-tools 3/3] osinfo-db-export: generate filename if none is given

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

 



Currently if no filename is given to the export command
the archive will be written to stdout, which is less than
helpful as default behaviour. Change it to generate a
suitable default filename. Export to stdout can still be
requested explicitly by giving a filename of '-'.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tools/osinfo-db-export.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/tools/osinfo-db-export.c b/tools/osinfo-db-export.c
index a789dfe..0d6d060 100644
--- a/tools/osinfo-db-export.c
+++ b/tools/osinfo-db-export.c
@@ -410,7 +410,7 @@ gint main(gint argc, gchar **argv)
     gboolean local = FALSE;
     gboolean system = FALSE;
     const gchar *root = "";
-    const gchar *archive = NULL;
+    gchar *archive = NULL;
     const gchar *custom = NULL;
     const gchar *version = NULL;
     gchar *autoversion = NULL;
@@ -477,7 +477,11 @@ gint main(gint argc, gchar **argv)
         version = autoversion;
     }
     prefix = g_strdup_printf("osinfo-db-%s", version);
-    archive = argc == 2 ? argv[1] : NULL;
+    if (argc == 2) {
+        archive = argv[2];
+    } else {
+        archive = g_strdup_printf("%s.tar.xz", prefix);
+    }
     dir = osinfo_db_get_path(root, user, local, system, custom);
     if (osinfo_db_export_create(prefix, version, dir, archive, verbose) < 0)
         goto error;
@@ -485,6 +489,7 @@ gint main(gint argc, gchar **argv)
     ret = EXIT_SUCCESS;
 
  error:
+    g_free(archive);
     g_free(autoversion);
     g_free(prefix);
     if (dir) {
@@ -506,7 +511,7 @@ osinfo-db-export - Export to a osinfo database archive
 
 =head1 SYNOPSIS
 
-osinfo-db-export [OPTIONS...] ARCHIVE-FILE
+osinfo-db-export [OPTIONS...] [ARCHIVE-FILE]
 
 =head1 DESCRIPTION
 
@@ -540,6 +545,9 @@ If run by a privileged account (ie root), the B<local> database
 location will be used by default, otherwise the B<user> location
 will be used.
 
+If no B<ARCHIVE-FILE> path is given, an automatically generated
+filename will be used, taking the format B<osinfo-db-$VERSION.tar.xz>.
+
 =head1 OPTIONS
 
 =over 8
-- 
2.7.4

_______________________________________________
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