diff mbox series

[uclient,1/2] uclient-fetch: fetch only header in spider mode

Message ID 20200703014238.19281-1-mans0n@gorani.run
State Under Review
Delegated to: Sungbo Eo
Headers show
Series [uclient,1/2] uclient-fetch: fetch only header in spider mode | expand

Commit Message

Sungbo Eo July 3, 2020, 1:42 a.m. UTC
Since spider mode only checks if a file exists, we don't need to download
the whole file. This also matches wget's behavior.

Signed-off-by: Sungbo Eo <mans0n@gorani.run>
---
v2: rebased
---
 uclient-fetch.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/uclient-fetch.c b/uclient-fetch.c
index 061f0fd..95334b0 100644
--- a/uclient-fetch.c
+++ b/uclient-fetch.c
@@ -235,8 +235,12 @@  static void header_done_cb(struct uclient *cl)
 		}
 	case 204:
 	case 200:
-		if (no_output)
+		if (no_output) {
+			if (!quiet)
+				fprintf(stderr, "Request succeeded\n");
+			request_done(cl);
 			break;
+		}
 
 		if (tb[H_LEN])
 			out_len = strtoul(blobmsg_get_string(tb[H_LEN]), NULL, 10);
@@ -265,7 +269,7 @@  static void read_data_cb(struct uclient *cl)
 	ssize_t n;
 	int len;
 
-	if (!no_output && output_fd < 0)
+	if (output_fd < 0)
 		return;
 
 	while (1) {
@@ -274,11 +278,9 @@  static void read_data_cb(struct uclient *cl)
 			return;
 
 		out_bytes += len;
-		if (!no_output) {
-			n = write(output_fd, buf, len);
-			if (n < 0)
-				return;
-		}
+		n = write(output_fd, buf, len);
+		if (n < 0)
+			return;
 	}
 }