Add -S flag; this is benign since fetch's behavior is unchanged if you

don't use it.  That's why I'm bringing it in during our "code slush"
Submitted by:	Stefan Esser <se@mi.uni-koeln.de>
This commit is contained in:
Jordan K. Hubbard 1998-09-20 00:01:26 +00:00
parent 2887f586f0
commit 0637c2cccd
5 changed files with 55 additions and 8 deletions

View File

@ -1,4 +1,4 @@
.\" $Id: fetch.1,v 1.22 1998/05/09 20:50:35 wollman Exp $
.\" $Id: fetch.1,v 1.23 1998/05/09 21:39:49 wollman Exp $
.Dd July 2, 1996
.Dt FETCH 1
.Os FreeBSD 2.2
@ -8,11 +8,13 @@
.Sh SYNOPSIS
.Nm fetch
.Op Fl MPabmnpqr
.Op Fl S Ar size
.Op Fl o Ar file
.Ar URL
.Op Ar ...
.Nm fetch
.Op Fl MPRmnpqr
.Op Fl S Ar size
.Op Fl o Ar file
.Op Fl c Ar dir
.Fl f Ar file
@ -99,6 +101,19 @@ The filenames specified are ``precious'', and should not be deleted
under any circumstances, even if the transfer failed or was incomplete.
.It Fl r
Restart a previously interrupted transfer.
.It Fl S Ar bytes
Require file size reported by
.Tn FTP
or
.Tn HTTP
server to match the value specified with this option.
On mismatch, a message is printed and the file will not be fetched.
If the server does not support reporting of file sizes, the option
will be ignored and the file will be retrieved anyway.
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 t
Work around a different set of buggy
.Tn TCP

View File

@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: fetch.h,v 1.4 1997/07/25 19:35:42 wollman Exp $
* $Id: fetch.h,v 1.5 1997/08/05 20:18:38 ache Exp $
*/
#ifndef fetch_h
@ -51,6 +51,7 @@ struct fetch_state {
int fs_auto_retry; /* -a option */
int fs_linux_bug; /* -b option */
int fs_use_connect; /* -t option */
off_t fs_expectedsize; /* -S option */
time_t fs_modtime;
void *fs_proto;
int (*fs_retrieve)(struct fetch_state *);

View File

@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ftp.c,v 1.8 1997/10/06 01:09:56 fenner Exp $
* $Id: ftp.c,v 1.9 1997/10/08 18:43:53 fenner Exp $
*/
#include <sys/types.h>
@ -375,6 +375,13 @@ ftp_retrieve(struct fetch_state *fs)
}
}
size = ftpGetSize(ftp, ftps->ftp_remote_file);
if (size > 0 && fs->fs_expectedsize != -1 && size != fs->fs_expectedsize) {
warnx("%s: size mismatch, expected=%lu / actual=%lu",
ftps->ftp_remote_path,
(unsigned long)fs->fs_expectedsize,
(unsigned long)size);
return EX_DATAERR;
}
modtime = ftpGetModtime(ftp, ftps->ftp_remote_file);
if (modtime <= 0) { /* xxx */
warnx("%s: cannot get remote modification time",

View File

@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: http.c,v 1.18 1998/05/09 20:50:37 wollman Exp $
* $Id: http.c,v 1.19 1998/07/12 09:07:36 se Exp $
*/
#include <sys/types.h>
@ -929,7 +929,20 @@ http_retrieve(struct fetch_state *fs)
free(base64ofmd5);
return EX_PROTOCOL;
}
if (total_length > 0 && fs->fs_expectedsize != -1
&& total_length != fs->fs_expectedsize) {
warnx("%s: size mismatch, expected=%lu / actual=%lu",
fs->fs_outputfile,
(unsigned long)fs->fs_expectedsize,
(unsigned long)total_length);
fclose(remote);
if (base64ofmd5)
free(base64ofmd5);
unsetup_sigalrm();
return EX_DATAERR;
}
fs->fs_status = "retrieving file from HTTP/1.x server";
/*

View File

@ -24,7 +24,7 @@
* SUCH DAMAGE.
*/
/* $Id: main.c,v 1.45 1998/05/09 08:41:23 des Exp $ */
/* $Id: main.c,v 1.46 1998/05/09 08:56:07 des Exp $ */
#include <sys/types.h>
@ -52,7 +52,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n",
"usage: fetch [-DHILMNPRTValmnpqrv] [-o outputfile]",
"usage: fetch [-DHILMNPRTValmnpqrv] [-o outputfile] [-S bytes]",
" [-f file -h host [-c dir] | URL]");
exit(EX_USAGE);
}
@ -71,9 +71,10 @@ main(int argc, char *const *argv)
init_schemes();
fs = clean_fetch_state;
fs.fs_verbose = 1;
fs.fs_expectedsize = -1;
change_to_dir = file_to_get = hostname = 0;
while ((c = getopt(argc, argv, "abc:D:f:h:HilLmMnNo:pPqRrtT:vV:")) != -1) {
while ((c = getopt(argc, argv, "abc:D:f:h:HilLmMnNo:pPqRrS:tT:vV:")) != -1) {
switch (c) {
case 'D': case 'H': case 'I': case 'N': case 'L': case 'V':
break; /* ncftp compatibility */
@ -134,6 +135,16 @@ main(int argc, char *const *argv)
fs.fs_use_connect = 1;
break;
case 'S':
/* strtol sets errno to ERANGE in the case of overflow */
errno = 0;
l = strtoul(optarg, &ep, 0);
if (!optarg[0] || *ep || errno != 0 || l > INT_MAX)
errx(EX_USAGE, "invalid size value: `%s'",
optarg);
fs.fs_expectedsize = l;
break;
case 'T':
/* strtol sets errno to ERANGE in the case of overflow */
errno = 0;