about summary refs log tree commit diff stats
path: root/src/tools/aesgcm_download.c
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-12-06 17:02:09 +0100
committerWilliam Wennerström <william@wstrm.dev>2020-12-06 17:02:09 +0100
commitac030378479cf999fefc0889d5c0932cfcabc4fc (patch)
treeaece65906a09f1fc01550e98ecda4511b352a8d7 /src/tools/aesgcm_download.c
parent1d2c0a8836123c3b484826b974f87a0061bc110b (diff)
downloadprofani-tty-ac030378479cf999fefc0889d5c0932cfcabc4fc.tar.gz
Rework url to filename
Diffstat (limited to 'src/tools/aesgcm_download.c')
-rw-r--r--src/tools/aesgcm_download.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c
index d75cabe3..f8d2db9f 100644
--- a/src/tools/aesgcm_download.c
+++ b/src/tools/aesgcm_download.c
@@ -85,11 +85,6 @@ aesgcm_file_get(void* userdata)
                                    "(%s).",
                                    https_url, g_strerror(errno));
         return NULL;
-    } else {
-        // TODO(wstrm): Maybe refactor this to use file handles so we do not
-        //              have to open a dummy file descriptor and then close it.
-        //              It's pretty ugly this way...
-        close(tmpfd);
     }
 
     FILE* outfh = fopen(aesgcm_dl->filename, "wb");
@@ -107,6 +102,7 @@ aesgcm_file_get(void* userdata)
     http_dl->worker = aesgcm_dl->worker;
     http_dl->url = strdup(https_url);
     http_dl->filename = strdup(tmpname);
+    http_dl->cmd_template = NULL;
 
     aesgcm_dl->http_dl = http_dl;
 
@@ -117,7 +113,7 @@ aesgcm_file_get(void* userdata)
         http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
                                    "Downloading '%s' failed: Unable to open "
                                    "temporary file at '%s' for reading (%s).",
-                                   aesgcm_dl->url, aesgcm_dl->filename,
+                                   aesgcm_dl->url, tmpname,
                                    g_strerror(errno));
         return NULL;
     }
@@ -130,6 +126,7 @@ aesgcm_file_get(void* userdata)
         cons_show_error(g_strerror(errno));
     }
 
+    close(tmpfd);
     remove(tmpname);
     g_free(tmpname);
 
@@ -149,7 +146,7 @@ aesgcm_file_get(void* userdata)
 
     if (aesgcm_dl->cmd_template != NULL) {
         gchar** argv = format_call_external_argv(aesgcm_dl->cmd_template,
-                                                 aesgcm_dl->url,
+                                                 aesgcm_dl->filename,
                                                  aesgcm_dl->filename);
 
         // TODO(wstrm): Log the error.
@@ -164,11 +161,11 @@ aesgcm_file_get(void* userdata)
         }
 
         g_strfreev(argv);
+        free(aesgcm_dl->cmd_template);
     }
 
     free(aesgcm_dl->filename);
     free(aesgcm_dl->url);
-    free(aesgcm_dl->cmd_template);
     free(aesgcm_dl);
 
     return NULL;