From nobody Wed May 8 14:53:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538988822926699.5650965012865; Mon, 8 Oct 2018 01:53:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA4973001711; Mon, 8 Oct 2018 08:53:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 538EB5C235; Mon, 8 Oct 2018 08:53:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B163A4CA95; Mon, 8 Oct 2018 08:53:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w988rbTH013126 for ; Mon, 8 Oct 2018 04:53:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C006309464F; Mon, 8 Oct 2018 08:53:37 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF509308BDA1; Mon, 8 Oct 2018 08:53:36 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 8 Oct 2018 10:53:25 +0200 Message-Id: <20181008085326.16139-2-fidencio@redhat.com> In-Reply-To: <20181008085326.16139-1-fidencio@redhat.com> References: <20181008085326.16139-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [osinfo-db-tools PATCH v2 1/2] import: Learn how to deal with URLs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 08 Oct 2018 08:53:41 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio --- tools/osinfo-db-import.c | 88 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/tools/osinfo-db-import.c b/tools/osinfo-db-import.c index 0d0bdd9..289a85d 100644 --- a/tools/osinfo-db-import.c +++ b/tools/osinfo-db-import.c @@ -135,6 +135,55 @@ static GFile *osinfo_db_import_get_file(GFile *target, return g_file_resolve_relative_path(target, tmp); } =20 +static int +osinfo_db_import_download_file(const gchar *url, + gchar **source_file) +{ + GFile *in =3D NULL; + GFile *out =3D NULL; + GError *err =3D NULL; + gchar *filename =3D NULL; + GFileCopyFlags flags =3D G_FILE_COPY_OVERWRITE | G_FILE_COPY_BACKUP; + int ret =3D -1; + + in =3D g_file_new_for_uri(url); + if (in =3D=3D NULL) + return -1; + + filename =3D g_file_get_basename(in); + if (filename =3D=3D NULL) + goto cleanup; + + *source_file =3D g_strdup_printf("%s/%s", g_get_user_cache_dir(), file= name); + if (*source_file =3D=3D NULL) + goto cleanup; + + out =3D g_file_new_for_path(*source_file); + if (out =3D=3D NULL) + goto cleanup; + + if (!g_file_copy(in, out, flags, NULL, NULL, NULL, &err)) { + g_printerr("Could not download the \"%s\" file: %s\n", + url, err->message); + goto cleanup; + } + + ret =3D 0; + + cleanup: + g_free(filename); + if (in !=3D NULL) + g_object_unref(in); + if (out !=3D NULL) + g_object_unref(out); + if (err !=3D NULL) + g_error_free(err); + if (ret !=3D 0) + unlink(*source_file); + + return ret; +} + static int osinfo_db_import_extract(GFile *target, const char *source, gboolean verbose) @@ -145,6 +194,8 @@ static int osinfo_db_import_extract(GFile *target, int r; GFile *file =3D NULL; GError *err =3D NULL; + gchar *source_file =3D NULL; + const gchar *uri_schemes[] =3D {"ftp", "http", NULL}; =20 arc =3D archive_read_new(); =20 @@ -154,9 +205,37 @@ static int osinfo_db_import_extract(GFile *target, if (source !=3D NULL && g_str_equal(source, "-")) source =3D NULL; =20 - if ((r =3D archive_read_open_filename(arc, source, 10240)) !=3D ARCHIV= E_OK) { + if (source !=3D NULL) { + gboolean download_file =3D FALSE; + + file =3D g_file_new_for_uri(source); + if (file =3D=3D NULL) + goto cleanup; + + /* The supported uri schemes here are "ftp", "http" and "https". + * However, "https" is not set as part of the array as it matches = with + * "http". */ + for (gint i =3D 0; uri_schemes[i] !=3D NULL; i++) { + if (g_file_has_uri_scheme(file, uri_schemes[i])) { + download_file =3D TRUE; + break; + } + } + + if (download_file) { + if (osinfo_db_import_download_file(source, &source_file) < 0) + goto cleanup; + } else { + source_file =3D g_strdup(source); + } + + if (source_file =3D=3D NULL) + goto cleanup; + } + + if ((r =3D archive_read_open_filename(arc, source_file, 10240)) !=3D A= RCHIVE_OK) { g_printerr("%s: cannot open archive %s: %s\n", - argv0, source, archive_error_string(arc)); + argv0, source_file, archive_error_string(arc)); goto cleanup; } =20 @@ -166,7 +245,7 @@ static int osinfo_db_import_extract(GFile *target, break; if (r !=3D ARCHIVE_OK) { g_printerr("%s: cannot read next archive entry in %s: %s\n", - argv0, source, archive_error_string(arc)); + argv0, source_file, archive_error_string(arc)); goto cleanup; } =20 @@ -180,7 +259,7 @@ static int osinfo_db_import_extract(GFile *target, =20 if (archive_read_close(arc) !=3D ARCHIVE_OK) { g_printerr("%s: cannot finish reading archive %s: %s\n", - argv0, source, archive_error_string(arc)); + argv0, source_file, archive_error_string(arc)); goto cleanup; } =20 @@ -191,6 +270,7 @@ static int osinfo_db_import_extract(GFile *target, g_error_free(err); if (file) g_object_unref(file); + g_free(source_file); return ret; } =20 --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 14:53:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538988830237992.1030224717159; Mon, 8 Oct 2018 01:53:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B9A630820C6; Mon, 8 Oct 2018 08:53:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CA8719940; Mon, 8 Oct 2018 08:53:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8457E4CAAD; Mon, 8 Oct 2018 08:53:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w988rc1u013133 for ; Mon, 8 Oct 2018 04:53:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 975DC308BDA1; Mon, 8 Oct 2018 08:53:38 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2F8530918E1; Mon, 8 Oct 2018 08:53:37 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 8 Oct 2018 10:53:26 +0200 Message-Id: <20181008085326.16139-3-fidencio@redhat.com> In-Reply-To: <20181008085326.16139-1-fidencio@redhat.com> References: <20181008085326.16139-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [osinfo-db-tools PATCH v2 2/2] import: Remove unused variable X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 08 Oct 2018 08:53:48 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio --- tools/osinfo-db-import.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/osinfo-db-import.c b/tools/osinfo-db-import.c index 289a85d..c0b4931 100644 --- a/tools/osinfo-db-import.c +++ b/tools/osinfo-db-import.c @@ -193,7 +193,6 @@ static int osinfo_db_import_extract(GFile *target, int ret =3D -1; int r; GFile *file =3D NULL; - GError *err =3D NULL; gchar *source_file =3D NULL; const gchar *uri_schemes[] =3D {"ftp", "http", NULL}; =20 @@ -266,8 +265,6 @@ static int osinfo_db_import_extract(GFile *target, ret =3D 0; cleanup: archive_read_free(arc); - if (err) - g_error_free(err); if (file) g_object_unref(file); g_free(source_file); --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list