~sircmpwn/gmni-devel

gmni: fix downloading of files v1 APPLIED

René Wagner: 1
 fix downloading of files

 1 files changed, 8 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/gmni-devel/patches/26015/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gmni] fix downloading of files Export this patch

due to the wrong handling in download_resp() files may get
broken (last chunk missing) and file descriptors have not
been closed correctly.

Additionally we now allow downloading of local ressources
as well - for what its worth.
---
 src/util.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/util.c b/src/util.c
index 8441b58..1d44c07 100644
--- a/src/util.c
+++ b/src/util.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "util.h"

void
@@ -83,10 +84,13 @@ download_resp(FILE *out, struct gemini_response resp, const char *path,
	fprintf(out, "Downloading %s to %s\n", url, path);
	char buf[BUFSIZ];
	for (int n = 1; n > 0;) {
		n = br_sslio_read(&resp.body, buf, sizeof(buf));
		if (n == -1) {
			fprintf(stderr, "Error: read\n");
			return 1;
		if (resp.sc) {
			n = br_sslio_read(&resp.body, buf, BUFSIZ);
		} else {
			n = read(resp.fd, buf, BUFSIZ);
		}
		if (n < 0) {
			break;
		}
		ssize_t w = 0;
		while (w < (ssize_t)n) {
-- 
2.33.1
Thanks!

To git@git.sr.ht:~sircmpwn/gmni
   41e5188..1a9aa3e  master -> master