diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-12-01 11:09:19 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-12-01 11:09:19 +0000 |
| commit | 20a2f25b54f7c9003587e7d68f475c722d0c5bce (patch) | |
| tree | 199402ebc28b400b5c19b9197a970da247c0d2af /usr.bin/fetch | |
| parent | a8d732a66e78fdc4e3d03f2091847e3cf8b31713 (diff) | |
Notes
Diffstat (limited to 'usr.bin/fetch')
| -rw-r--r-- | usr.bin/fetch/fetch.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index b33fb037850b..c24d288659a4 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -259,10 +259,12 @@ fetch(char *URL, char *path) * sure the local file was a truncated copy of the remote file; we * can drop the connection later if we change our minds. */ - if (r_flag && !o_stdout && stat(path, &sb) != -1) - url->offset = sb.st_size; - else - sb.st_size = 0; + if ((r_flag || m_flag) && !o_stdout && stat(path, &sb) != -1) { + if (r_flag) + url->offset = sb.st_size; + } else { + sb.st_size = -1; + } /* start the transfer */ if ((f = fetchXGet(url, &us, flags)) == NULL) { @@ -294,16 +296,18 @@ fetch(char *URL, char *path) } if (v_level > 1) { - if (sb.st_size) - warnx("local: %lld / %ld", sb.st_size, sb.st_mtime); - warnx("remote: %lld / %ld", us.size, us.mtime); + if (sb.st_size != -1) + fprintf(stderr, "local size / mtime: %lld / %ld\n", + sb.st_size, sb.st_mtime); + fprintf(stderr, "remote size / mtime: %lld / %ld\n", + us.size, us.mtime); } /* open output file */ if (o_stdout) { /* output to stdout */ of = stdout; - } else if (sb.st_size) { + } else if (sb.st_size != -1) { /* resume mode, local file exists */ if (!F_flag && us.mtime && sb.st_mtime != us.mtime) { /* no match! have to refetch */ @@ -341,7 +345,7 @@ fetch(char *URL, char *path) } } } - if (m_flag && stat(path, &sb) != -1) { + if (m_flag && sb.st_size != -1) { /* mirror mode, local file exists */ if (sb.st_size == us.size && sb.st_mtime == us.mtime) goto success; @@ -384,7 +388,7 @@ fetch(char *URL, char *path) stat_end(&xs); - /* Set mtime of local file */ + /* set mtime of local file */ if (!n_flag && us.mtime && !o_stdout && (stat(path, &sb) != -1) && sb.st_mode & S_IFREG) { struct timeval tv[2]; @@ -423,6 +427,15 @@ fetch(char *URL, char *path) goto failure_keep; } + /* + * If the transfer timed out and we didn't know how much to + * expect, assume the worst (i.e. we didn't get all of it) + */ + if (sigalrm && us.size == -1) { + warnx("%s may be truncated", path); + goto failure_keep; + } + success: r = 0; goto done; @@ -596,7 +609,7 @@ main(int argc, char *argv[]) errx(1, "invalid hostname"); if (asprintf(argv, "ftp://%s/%s/%s", h_hostname, c_dirname ? c_dirname : "", f_filename) == -1) - errx(1, strerror(ENOMEM)); + errx(1, "%s", strerror(ENOMEM)); argc++; } @@ -609,7 +622,7 @@ main(int argc, char *argv[]) if (B_size < MINBUFSIZE) B_size = MINBUFSIZE; if ((buf = malloc(B_size)) == NULL) - errx(1, strerror(ENOMEM)); + errx(1, "%s", strerror(ENOMEM)); /* timeouts */ if ((s = getenv("FTP_TIMEOUT")) != NULL) { |
