diff options
| author | Martin Cracauer <cracauer@FreeBSD.org> | 2000-03-20 15:45:19 +0000 |
|---|---|---|
| committer | Martin Cracauer <cracauer@FreeBSD.org> | 2000-03-20 15:45:19 +0000 |
| commit | 0d82a4031c572a7571a564e42492411a7cac004d (patch) | |
| tree | ad28da8478cc7861cb6524ba6dbea3e77e71a093 /usr.bin | |
| parent | 96fbc99809a518107f3789ccb0c2d79ba7f41d90 (diff) | |
Notes
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/fetch/fetch.h | 2 | ||||
| -rw-r--r-- | usr.bin/fetch/ftp.c | 3 | ||||
| -rw-r--r-- | usr.bin/fetch/http.c | 7 | ||||
| -rw-r--r-- | usr.bin/fetch/main.c | 54 |
4 files changed, 44 insertions, 22 deletions
diff --git a/usr.bin/fetch/fetch.h b/usr.bin/fetch/fetch.h index bea7db93a38e..e0b847d260c5 100644 --- a/usr.bin/fetch/fetch.h +++ b/usr.bin/fetch/fetch.h @@ -77,7 +77,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 922887bb2789..7abab354fdbb 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 4e19485a9f8f..fdb526a8ca9a 100644 --- a/usr.bin/fetch/http.c +++ b/usr.bin/fetch/http.c @@ -1027,7 +1027,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 7cae99ba4e06..5f69d97673bd 100644 --- a/usr.bin/fetch/main.c +++ b/usr.bin/fetch/main.c @@ -310,8 +310,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; @@ -322,9 +325,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); @@ -337,13 +343,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 @@ -351,26 +358,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) @@ -378,5 +388,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; } - |
