diff mbox series

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

Message ID 20200106134016.11354-1-mans0n@gorani.run
State Superseded
Headers show
Series [OpenWrt-Devel,uclient,1/2] uclient-fetch: fetch only header in spider mode | expand

Commit Message

Sungbo Eo Jan. 6, 2020, 1:40 p.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>
---
 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 38c9c53..3718197 100644
--- a/uclient-fetch.c
+++ b/uclient-fetch.c
@@ -234,8 +234,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);
@@ -264,7 +268,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) {
@@ -273,11 +277,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;
 	}
 }