diff options
author | Leandro Pereira <leandro@hardinfo.org> | 2020-05-13 22:17:36 -0700 |
---|---|---|
committer | Leandro Pereira <leandro@hardinfo.org> | 2020-05-13 22:17:36 -0700 |
commit | a19233d7013aad91d4cfa80d216070caa6a8c141 (patch) | |
tree | 5afa785e7d5c81d7827ea055a857ac86d6bdfb7b /shell | |
parent | ac136d3af017778d91fc3fa9eda4988059532646 (diff) |
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.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/syncmanager.c | 14 |
1 files changed, 11 insertions, 3 deletions
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); |