summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcracauer <cracauer@FreeBSD.org>2000-03-08 13:02:11 +0000
committercracauer <cracauer@FreeBSD.org>2000-03-08 13:02:11 +0000
commit1a6acdd95fbe8b2547544db42a78d77f65da9924 (patch)
tree1f681fd05aaafb6597069f9e3a9ef09c35f2602f /usr.bin
parentce4fd272577d7c5ecf7b29ac297959663b5ba67a (diff)
downloadFreeBSD-src-1a6acdd95fbe8b2547544db42a78d77f65da9924.zip
FreeBSD-src-1a6acdd95fbe8b2547544db42a78d77f65da9924.tar.gz
Print a warning and exit with != 0 when at least one downloaded file
is shorter than previously announced by the server. Tested by asami. Approved by: jkh
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/fetch/fetch.h2
-rw-r--r--usr.bin/fetch/ftp.c3
-rw-r--r--usr.bin/fetch/http.c7
-rw-r--r--usr.bin/fetch/main.c54
4 files changed, 44 insertions, 22 deletions
diff --git a/usr.bin/fetch/fetch.h b/usr.bin/fetch/fetch.h
index 22e4294..d54a343 100644
--- a/usr.bin/fetch/fetch.h
+++ b/usr.bin/fetch/fetch.h
@@ -78,7 +78,7 @@ extern struct uri_scheme file_scheme, ftp_scheme, http_scheme;
void adjmodtime(struct fetch_state *fs);
void catchsig(int signo);
-void display(struct fetch_state *fs, off_t total, ssize_t thisincr);
+int display(struct fetch_state *fs, off_t total, ssize_t thisincr);
void init_schemes(void);
void rm(struct fetch_state *fs);
void setup_sigalrm(void);
diff --git a/usr.bin/fetch/ftp.c b/usr.bin/fetch/ftp.c
index 922887b..7abab35 100644
--- a/usr.bin/fetch/ftp.c
+++ b/usr.bin/fetch/ftp.c
@@ -514,7 +514,8 @@ ftp_retrieve(struct fetch_state *fs)
fclose(local);
fclose(remote);
fclose(ftp);
- display(fs, size, -1);
+ if (display(fs, size, -1) != 0)
+ return EX_PROTOCOL;
adjmodtime(fs);
return 0;
}
diff --git a/usr.bin/fetch/http.c b/usr.bin/fetch/http.c
index 3025ecc..e7d5f8b 100644
--- a/usr.bin/fetch/http.c
+++ b/usr.bin/fetch/http.c
@@ -1029,7 +1029,12 @@ spewerror:
goto out;
status = errno; /* save errno for warn(), below, if needed */
- display(fs, total_length, -1); /* do here in case we have to warn */
+ if (display(fs, total_length, -1) != 0) {
+ /* Check for truncated file */
+ errno = status;
+ status = EX_PROTOCOL;
+ goto out;
+ }
errno = status;
if (ferror(remote)) {
diff --git a/usr.bin/fetch/main.c b/usr.bin/fetch/main.c
index 63c7aee..1df192c 100644
--- a/usr.bin/fetch/main.c
+++ b/usr.bin/fetch/main.c
@@ -314,8 +314,11 @@ catchsig(int sig)
siglongjmp(sigbuf, sig);
}
-/* Used to generate the progress display when not in quiet mode. */
-void
+/*
+ * Used to generate the progress display when not in quiet mode.
+ * Return != 0 when the file appears to be truncated.
+ */
+int
display(struct fetch_state *fs, off_t size, ssize_t n)
{
static off_t bytes;
@@ -326,9 +329,12 @@ display(struct fetch_state *fs, off_t size, ssize_t n)
struct timezone tz;
struct timeval t;
float d;
-
- if (!fs->fs_verbose)
- return;
+ int truncated;
+
+ if (size != -1 && n == -1 && bytes != size) {
+ truncated = 1;
+ } else
+ truncated = 0;
if (init == 0) {
init = 1;
gettimeofday(&t0, &tz);
@@ -341,13 +347,14 @@ display(struct fetch_state *fs, off_t size, ssize_t n)
size ? "" : " [appending]");
else
asprintf (&s, "Receiving %s", fs->fs_outputfile);
- fprintf (stderr, "%s", s);
+ if (fs->fs_verbose)
+ fprintf (stderr, "%s", s);
bytestart = bytes = n;
- return;
+ goto out;
}
gettimeofday(&t, &tz);
if (n == -1) {
- if(stdoutatty) {
+ if(stdoutatty && fs->fs_verbose) {
if (size > 0)
fprintf (stderr, "\r%s: 100%%", s);
else
@@ -355,26 +362,29 @@ display(struct fetch_state *fs, off_t size, ssize_t n)
}
bytes -= bytestart;
d = t.tv_sec + t.tv_usec/1.e6 - t_start.tv_sec - t_start.tv_usec/1.e6;
- fprintf (stderr, "\n%qd bytes transferred in %.1f seconds",
- (long long)bytes, d);
+ if (fs->fs_verbose)
+ fprintf (stderr, "\n%qd bytes transferred in %.1f seconds",
+ (long long)bytes, d);
d = bytes/d;
- if (d < 1000)
- fprintf (stderr, " (%.0f bytes/s)\n", d);
- else {
- d /=1024;
- fprintf (stderr, " (%.2f Kbytes/s)\n", d);
+ if (fs->fs_verbose) {
+ if (d < 1000)
+ fprintf (stderr, " (%.0f bytes/s)\n", d);
+ else {
+ d /=1024;
+ fprintf (stderr, " (%.2f Kbytes/s)\n", d);
+ }
}
free(s);
init = 0;
- return;
+ goto out;
}
bytes += n;
d = t.tv_sec + t.tv_usec/1.e6 - t0.tv_sec - t0.tv_usec/1.e6;
if (d < 5) /* display every 5 sec. */
- return;
+ goto out;
t0 = t;
pr++;
- if(stdoutatty) {
+ if(stdoutatty && fs->fs_verbose) {
if (size > 1000000)
fprintf (stderr, "\r%s: %2qd%%", s, (long long)(bytes/(size/100)));
else if (size > 0)
@@ -382,5 +392,11 @@ display(struct fetch_state *fs, off_t size, ssize_t n)
else
fprintf (stderr, "\r%s: %qd Kbytes", s, (long long)(bytes/1024));
}
+out:
+ if (truncated != 0)
+ fprintf(stderr, "WARNING: File %s appears to be truncated: "
+ "%qd/%qd bytes\n",
+ fs->fs_outputfile,
+ (quad_t)bytes, (quad_t)size);
+ return truncated;
}
-
OpenPOWER on IntegriCloud