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

Sungbo Eo mans0n at gorani.run
Thu Jul 2 21:42:37 EDT 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>
---
v2: rebased
---
 uclient-fetch.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

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




More information about the openwrt-devel mailing list