From a19233d7013aad91d4cfa80d216070caa6a8c141 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Wed, 13 May 2020 22:17:36 -0700 Subject: Splice contents from downloads into recently-created files When testing in another computer, these files were always empty. Turns out they were not being overwritten in my main computer, so the data received by libsoup was never written to these files... d'oh. (They were there in one computer because this function was written slightly differently before.) Also plugs one memory leak. --- shell/syncmanager.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'shell/syncmanager.c') diff --git a/shell/syncmanager.c b/shell/syncmanager.c index 226cb342..e2dabd7a 100644 --- a/shell/syncmanager.c +++ b/shell/syncmanager.c @@ -240,6 +240,8 @@ static void got_response(GObject *source, GAsyncResult *res, gpointer user_data) GInputStream *is; is = soup_session_send_finish(session, res, &sna->error); + if (is == NULL) + goto out; if (sna->error != NULL) goto out; @@ -247,9 +249,15 @@ static void got_response(GObject *source, GAsyncResult *res, gpointer user_data) gchar *path = g_build_filename(g_get_user_config_dir(), "hardinfo", sna->entry->file_name, NULL); GFile *file = g_file_new_for_path(path); - - g_file_replace(file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, - NULL, &sna->error); + GFileOutputStream *output = + g_file_replace(file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, + NULL, &sna->error); + + if (output != NULL) { + g_output_stream_splice(output, is, + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, + &sna->error); + } g_free(path); g_object_unref(file); -- cgit v1.2.3