summaryrefslogtreecommitdiffstats
path: root/usr.bin/fetch
diff options
context:
space:
mode:
authorcracauer <cracauer@FreeBSD.org>1998-12-08 13:00:49 +0000
committercracauer <cracauer@FreeBSD.org>1998-12-08 13:00:49 +0000
commitc4f0cd91dfd075657106a1cf7a6b6e0b3a1712f9 (patch)
treefc3f9e64c7788a6155478c488fe7065670d41463 /usr.bin/fetch
parentb34285d7af1280b5524d2efb346146f3bb7834e1 (diff)
downloadFreeBSD-src-c4f0cd91dfd075657106a1cf7a6b6e0b3a1712f9.zip
FreeBSD-src-c4f0cd91dfd075657106a1cf7a6b6e0b3a1712f9.tar.gz
Add -s option, just report size of file that would be fetched.
Reviewed by: -current list
Diffstat (limited to 'usr.bin/fetch')
-rw-r--r--usr.bin/fetch/fetch.15
-rw-r--r--usr.bin/fetch/fetch.h3
-rw-r--r--usr.bin/fetch/ftp.c16
-rw-r--r--usr.bin/fetch/http.c40
-rw-r--r--usr.bin/fetch/main.c11
5 files changed, 67 insertions, 8 deletions
diff --git a/usr.bin/fetch/fetch.1 b/usr.bin/fetch/fetch.1
index 06a2fc0..ccbc80c 100644
--- a/usr.bin/fetch/fetch.1
+++ b/usr.bin/fetch/fetch.1
@@ -1,4 +1,4 @@
-.\" $Id: fetch.1,v 1.24 1998/09/20 00:01:26 jkh Exp $
+.\" $Id: fetch.1,v 1.25 1998/11/08 23:18:47 des Exp $
.Dd July 2, 1996
.Dt FETCH 1
.Os FreeBSD 2.2
@@ -115,6 +115,9 @@ This option is useful to prevent
.Nm fetch
from downloading a file that is either incomplete or the wrong version,
given the correct size of the file in advance.
+.It Fl s
+Ask server for size of file in bytes and print it to stdout. Do not
+actually fetch the file.
.It Fl T Ar seconds
Set timeout value to
.Ar seconds.
diff --git a/usr.bin/fetch/fetch.h b/usr.bin/fetch/fetch.h
index aac3fbc..685fdd6 100644
--- a/usr.bin/fetch/fetch.h
+++ b/usr.bin/fetch/fetch.h
@@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: fetch.h,v 1.5 1997/08/05 20:18:38 ache Exp $
+ * $Id: fetch.h,v 1.6 1998/09/20 00:01:26 jkh Exp $
*/
#ifndef fetch_h
@@ -52,6 +52,7 @@ struct fetch_state {
int fs_linux_bug; /* -b option */
int fs_use_connect; /* -t option */
off_t fs_expectedsize; /* -S option */
+ int fs_reportsize; /* -s option */
time_t fs_modtime;
void *fs_proto;
int (*fs_retrieve)(struct fetch_state *);
diff --git a/usr.bin/fetch/ftp.c b/usr.bin/fetch/ftp.c
index 6c6c71c..45c8ecf 100644
--- a/usr.bin/fetch/ftp.c
+++ b/usr.bin/fetch/ftp.c
@@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ftp.c,v 1.9 1997/10/08 18:43:53 fenner Exp $
+ * $Id: ftp.c,v 1.10 1998/09/20 00:01:26 jkh Exp $
*/
#include <sys/types.h>
@@ -375,6 +375,20 @@ ftp_retrieve(struct fetch_state *fs)
}
}
size = ftpGetSize(ftp, ftps->ftp_remote_file);
+
+ if (fs->fs_reportsize) {
+ fclose(ftp);
+ if (size == -1) {
+ warnx("%s: size not known\n", fs->fs_outputfile);
+ printf("Unknown\n");
+ return 1;
+ }
+ else {
+ printf("%qd\n", (quad_t)size);
+ return 0;
+ }
+ }
+
if (size > 0 && fs->fs_expectedsize != -1 && size != fs->fs_expectedsize) {
warnx("%s: size mismatch, expected=%lu / actual=%lu",
ftps->ftp_remote_path,
diff --git a/usr.bin/fetch/http.c b/usr.bin/fetch/http.c
index 24b63eb..ff8d25f 100644
--- a/usr.bin/fetch/http.c
+++ b/usr.bin/fetch/http.c
@@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: http.c,v 1.20 1998/09/20 00:01:26 jkh Exp $
+ * $Id: http.c,v 1.21 1998/10/26 02:39:21 fenner Exp $
*/
#include <sys/types.h>
@@ -440,6 +440,7 @@ http_retrieve(struct fetch_state *fs)
char *base64ofmd5;
int to_stdout, restarting, redirection, retrying, autherror, chunked;
char rangebuf[sizeof("Range: bytes=18446744073709551616-\r\n")];
+ int tried_head;
setup_http_auth();
@@ -448,6 +449,7 @@ http_retrieve(struct fetch_state *fs)
restarting = fs->fs_restart;
redirection = 0;
retrying = 0;
+ tried_head = 0;
/*
* Figure out the timeout. Prefer the -T command-line value,
@@ -507,7 +509,14 @@ http_retrieve(struct fetch_state *fs)
} while(0)
retry:
- addstr(iov, n, "GET ");
+ if (fs->fs_reportsize && !tried_head) {
+ addstr(iov, n, "HEAD ");
+ tried_head = 1;
+ }
+ else {
+ addstr(iov, n, "GET ");
+ tried_head = 0;
+ }
addstr(iov, n, https->http_remote_request);
addstr(iov, n, " HTTP/1.1\r\n");
/*
@@ -738,6 +747,16 @@ got100reply:
else
autherror = 407;
break;
+ case 501: /* Not Implemented */
+ /* If we tried HEAD, retry with GET */
+ if (tried_head) {
+ n = 0;
+ goto retry;
+ }
+ else {
+ errstr = safe_strdup(line);
+ break;
+ }
case 503: /* Service Unavailable */
if (!fs->fs_auto_retry)
errstr = safe_strdup(line);
@@ -945,6 +964,23 @@ spewerror:
fs->fs_status = "retrieving file from HTTP/1.x server";
+ if (fs->fs_reportsize) {
+ if (total_length == -1) {
+ warnx("%s: size not known\n",
+ fs->fs_outputfile);
+ printf("Unknown\n");
+ status = 1;
+ }
+ else {
+ printf("%qd\n", (quad_t)total_length);
+ status = 0;
+ }
+ fclose(remote);
+ unsetup_sigalrm();
+ return status;
+ }
+
+
/*
* OK, if we got here, then we have finished parsing the header
* and have read the `\r\n' line which denotes the end of same.
diff --git a/usr.bin/fetch/main.c b/usr.bin/fetch/main.c
index 0d2e69a..8b24dad 100644
--- a/usr.bin/fetch/main.c
+++ b/usr.bin/fetch/main.c
@@ -24,7 +24,7 @@
* SUCH DAMAGE.
*/
-/* $Id: main.c,v 1.47 1998/09/20 00:01:26 jkh Exp $ */
+/* $Id: main.c,v 1.48 1998/11/08 23:18:48 des Exp $ */
#include <sys/types.h>
@@ -52,7 +52,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n",
- "usage: fetch [-DHILMNPRTVablmnpqrtv] [-o outputfile] [-S bytes]",
+ "usage: fetch [-DHILMNPRTVablmnpqrstv] [-o outputfile] [-S bytes]",
" [-f file -h host [-c dir] | URL]");
exit(EX_USAGE);
}
@@ -71,10 +71,11 @@ main(int argc, char *const *argv)
init_schemes();
fs = clean_fetch_state;
fs.fs_verbose = 1;
+ fs.fs_reportsize = 0;
fs.fs_expectedsize = -1;
change_to_dir = file_to_get = hostname = 0;
- while ((c = getopt(argc, argv, "abc:D:f:h:HIlLmMnNo:pPqRrS:tT:vV:")) != -1) {
+ while ((c = getopt(argc, argv, "abc:D:f:h:HIlLmMnNo:pPqRrS:stT:vV:")) != -1) {
switch (c) {
case 'D': case 'H': case 'I': case 'L': case 'N': case 'V':
break; /* ncftp compatibility */
@@ -135,6 +136,10 @@ main(int argc, char *const *argv)
fs.fs_use_connect = 1;
break;
+ case 's':
+ fs.fs_reportsize = 1;
+ break;
+
case 'S':
/* strtol sets errno to ERANGE in the case of overflow */
errno = 0;
OpenPOWER on IntegriCloud