shithub: s3

Download patch

ref: 7da959bcd38cc76cb2d3cf4d6fee44c84bfbecf8
parent: 57bffefe7e30fae10caae16aa36fcb1150ddc46f
author: Jacob Moody <moody@posixcafe.org>
date: Mon Nov 24 01:04:06 EST 2025

Change common flags to not conflict with stnadard fs flags and dump error on download error

--- a/cmd.c
+++ b/cmd.c
@@ -21,13 +21,34 @@
 	}
 }
 
+static void
+dumperr(Hcon *con)
+{
+	long n;
+	char data[8192];
+
+	for(;;){
+		n = read(con->err, data, sizeof data);
+		if(n < 0)
+			sysfatal("download errorbody: %r");
+		if(n == 0){
+			hclose(con);
+			fprint(2, "\n");
+			return;
+		}
+		fprint(2, "%.*s", (int)n, data);
+	}
+}
+
 void
 download(S3 *s3, char *path, Biobuf *local, int (*fn)(S3*,Hcon*,char*))
 {
 	Hcon con;
 
-	if(fn(s3, &con, path) < 0)
-		sysfatal("failed to create request: %r");
+	if(fn(s3, &con, path) < 0){
+		dumperr(&con);
+		sysfatal("could not create request: %r");
+	}
 	dump(&con, local);
 }
 
@@ -67,15 +88,15 @@
 	initial = argc;
 	s3->access = s3->endpoint = s3->region = nil;
 	ARGBEGIN{
-	case 'a':
+	case 'e':
+		s3->region = strdup(EARGF(usage()));
+		break;
+	case 'k':
 		s3->access = strdup(EARGF(usage()));
 		break;
 	case 'u':
 		s3->endpoint = strdup(EARGF(usage()));
 		break;
-	case 'r':
-		s3->region = strdup(EARGF(usage()));
-		break;
 	}ARGEND
 
 	if(s3->access == nil)
@@ -85,8 +106,10 @@
 	if(s3->region)
 		s3->region = getenv("AWS_DEFAULT_REGION");
 
-	if(s3->access == nil || s3->endpoint == nil)
-		usage();
+	if(s3->access == nil || s3->endpoint == nil){
+		fprint(2, "no access key and/or no endpoint defined\n");
+		exits("usage");
+	}
 	if(s3->region == nil)
 		s3->region = strdup("auto");
 
--- a/s3.1
+++ b/s3.1
@@ -104,13 +104,13 @@
 These parameters may be specified using either their standard environment variable names, or
 through command line flags.
 $AWS_ACCESS_KEY_ID and the
-.B -a
+.B -k
 flag may be used to specify the access id.
 $AWS_ENDPOINT_URL_S3 and the
 .B -u
 flag may be used to specify the endpoint url.
 $AWS_DEFAULT_REGION and the
-.B -r
+.B -e
 flag may be used to specify the region, defaulting to "auto" if not set.
 .SH "SEE ALSO"
 .IR webfs (4),
--