[gnome-software: 4/8] gs-plugin: Refactor download code to use gs_download_file_async()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 4/8] gs-plugin: Refactor download code to use gs_download_file_async()
- Date: Fri, 25 Feb 2022 12:33:49 +0000 (UTC)
commit 50e477a984d306f79b005705436c654063303ef6
Author: Philip Withnall <pwithnall endlessos org>
Date: Sun Feb 20 18:02:14 2022 +0000
gs-plugin: Refactor download code to use gs_download_file_async()
This should introduce no functional changes. It’s a step towards
dropping `gs_plugin_download_file()`.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gs-plugin.c | 37 ++++++-------------------------------
1 file changed, 6 insertions(+), 31 deletions(-)
---
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 8d2c6a178..60fa72367 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -980,13 +980,10 @@ gs_plugin_download_file (GsPlugin *plugin,
{
g_autoptr(SoupSession) soup_session = NULL;
g_autoptr(GFile) output_file = NULL;
- g_autoptr(GFileOutputStream) output_stream = NULL;
- g_autofree gchar *last_etag = NULL;
g_autoptr(GAsyncResult) result = NULL;
g_autoptr(GMainContext) context = g_main_context_new ();
g_autoptr(GMainContextPusher) context_pusher = g_main_context_pusher_new (context);
GsPluginDownloadHelper helper;
- g_autofree gchar *new_etag = NULL;
g_autoptr(GError) local_error = NULL;
helper.plugin = plugin;
@@ -994,36 +991,17 @@ gs_plugin_download_file (GsPlugin *plugin,
soup_session = gs_build_soup_session ();
- /* Create the destination file’s directory. */
- if (!gs_mkdir_parent (filename, error))
- return FALSE;
-
- /* Query the old ETag if the file already exists. */
- last_etag = gs_utils_get_file_etag (output_file, cancellable);
-
- /* Create the output file. */
- output_stream = g_file_replace (output_file, last_etag, FALSE,
- G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION,
- cancellable, &local_error);
-
- if (output_stream == NULL) {
- g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_DOWNLOAD_FAILED,
- local_error->message);
- return FALSE;
- }
-
/* Do the download. */
- gs_download_stream_async (soup_session, uri, G_OUTPUT_STREAM (output_stream),
- last_etag, G_PRIORITY_LOW,
- download_file_progress_cb, &helper,
- cancellable, async_result_cb, &result);
+ output_file = g_file_new_for_path (filename);
+ gs_download_file_async (soup_session, uri, output_file,
+ G_PRIORITY_LOW,
+ download_file_progress_cb, &helper,
+ cancellable, async_result_cb, &result);
while (result == NULL)
g_main_context_iteration (context, TRUE);
- if (!gs_download_stream_finish (soup_session, result, &new_etag, &local_error)) {
+ if (!gs_download_file_finish (soup_session, result, &local_error)) {
g_set_error_literal (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_DOWNLOAD_FAILED,
@@ -1031,9 +1009,6 @@ gs_plugin_download_file (GsPlugin *plugin,
return FALSE;
}
- /* Update the ETag. */
- gs_utils_set_file_etag (output_file, new_etag, cancellable);
-
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]