Re: [PATCH db-tools] osinfo-db-export: add ability to include a license file

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

 



On Wed, Oct 19, 2016 at 11:11 AM, Daniel P. Berrange
<berrange@xxxxxxxxxx> wrote:
> Add a "--license FILE-NAME" option to osinfo-db-export
> which will add that reference FILE-NAME to the generated
> archive as a file called "LICENSE" in the top level.
>
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  tools/osinfo-db-export.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 77 insertions(+), 1 deletion(-)
>
> diff --git a/tools/osinfo-db-export.c b/tools/osinfo-db-export.c
> index a2aef2f..8b2d5fb 100644
> --- a/tools/osinfo-db-export.c
> +++ b/tools/osinfo-db-export.c
> @@ -336,10 +336,72 @@ static int osinfo_db_export_create_version(const gchar *prefix,
>      return ret;
>  }
>
> +static int osinfo_db_export_create_license(const gchar *prefix,
> +                                           const gchar *license,
> +                                           const gchar *target,
> +                                           struct archive *arc,
> +                                           gboolean verbose)
> +{
> +    int ret = -1;
> +    struct archive_entry *entry = NULL;
> +    gchar *entpath = NULL;
> +    GFile *file = NULL;
> +    GFileInfo *info = NULL;
> +    GError *err = NULL;
> +
> +    file = g_file_new_for_path(license);
> +
> +    info = g_file_query_info(file,
> +                             G_FILE_ATTRIBUTE_STANDARD_NAME
> +                             ","
> +                             G_FILE_ATTRIBUTE_STANDARD_SIZE,
> +                             G_FILE_QUERY_INFO_NONE,
> +                             NULL,
> +                             &err);
> +    if (!info) {
> +        g_printerr("%s: cannot get file info %s: %s\n",
> +                   argv0, license, err->message);
> +        goto cleanup;
> +    }
> +
> +    entpath = g_strdup_printf("%s/LICENSE", prefix);
> +    entry = archive_entry_new();
> +    archive_entry_set_pathname(entry, entpath);
> +
> +    archive_entry_set_atime(entry, entryts, 0);
> +    archive_entry_set_ctime(entry, entryts, 0);
> +    archive_entry_set_mtime(entry, entryts, 0);
> +    archive_entry_set_birthtime(entry, entryts, 0);
> +
> +    if (verbose) {
> +        g_print("%s: r %s\n", argv0, entpath);
> +    }
> +    archive_entry_set_filetype(entry, AE_IFREG);
> +    archive_entry_set_perm(entry, 0644);
> +    archive_entry_set_size(entry, g_file_info_get_size(info));
> +
> +    if (archive_write_header(arc, entry) != ARCHIVE_OK) {
> +        g_printerr("%s: cannot write archive header %s: %s\n",
> +                   argv0, target, archive_error_string(arc));
> +        goto cleanup;
> +    }
> +
> +    if (osinfo_db_export_create_reg(file, license, target, arc) < 0)
> +        goto cleanup;
> +
> +    ret = 0;
> + cleanup:
> +    archive_entry_free(entry);
> +    if (err)
> +        g_error_free(err);
> +    return ret;
> +}
> +
>  static int osinfo_db_export_create(const gchar *prefix,
>                                     const gchar *version,
>                                     GFile *source,
>                                     const gchar *target,
> +                                   const gchar *license,
>                                     gboolean verbose)
>  {
>      struct archive *arc;
> @@ -369,6 +431,11 @@ static int osinfo_db_export_create(const gchar *prefix,
>          goto cleanup;
>      }
>
> +    if (license != NULL &&
> +        osinfo_db_export_create_license(prefix, license, target, arc, verbose) < 0) {
> +        goto cleanup;
> +    }
> +
>      if (archive_write_close(arc) != ARCHIVE_OK) {
>          g_printerr("%s: cannot finish writing archive %s: %s\n",
>                     argv0, target, archive_error_string(arc));
> @@ -415,6 +482,7 @@ gint main(gint argc, gchar **argv)
>      const gchar *version = NULL;
>      gchar *autoversion = NULL;
>      gchar *prefix = NULL;
> +    const gchar *license = NULL;
>      int locs = 0;
>      GFile *dir = NULL;
>      const GOptionEntry entries[] = {
> @@ -432,6 +500,8 @@ gint main(gint argc, gchar **argv)
>          N_("Set version number of archive"), NULL, },
>        { "root", 0, 0, G_OPTION_ARG_STRING, &root,
>          N_("Installation root directory"), NULL, },
> +      { "license", 0, 0, G_OPTION_ARG_STRING, &license,
> +        N_("License file"), NULL, },
>        { NULL, 0, 0, 0, NULL, NULL, NULL },
>      };
>      argv0 = argv[0];
> @@ -483,7 +553,8 @@ gint main(gint argc, gchar **argv)
>          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)
> +    if (osinfo_db_export_create(prefix, version, dir, archive,
> +                                license, verbose) < 0)
>          goto error;
>
>      ret = EXIT_SUCCESS;
> @@ -584,6 +655,11 @@ Set the version string for the files in the archive to
>  B<VERSION>. If this argument is not given, the version
>  will be set to the current date in the format B<YYYYMMDD>.
>
> +=item B<--license=LICENSE-FILE>
> +
> +Add C<LICENSE-FILE> to the generated archive as an entry
> +named "LICENSE".
> +
>  =item B<-v>, B<--verbose>
>
>  Display verbose progress information when archiving files
> --
> 2.7.4
>
> _______________________________________________
> Libosinfo mailing list
> Libosinfo@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libosinfo

ACK!

_______________________________________________
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