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

Sungbo Eo mans0n at gorani.run
Mon Jan 6 08:40:15 EST 2020


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 at gorani.run>
---
 uclient-fetch.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

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;
 	}
 }
 
-- 
2.24.1

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list