diff options
author | des <des@FreeBSD.org> | 2000-07-19 23:56:45 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-07-19 23:56:45 +0000 |
commit | 3ce22a8bc5d1323c5a08611b3eb039b507d894b4 (patch) | |
tree | 0149f260f6c43c6e3a96ed050ecec2b00398a109 /usr.bin/fetch/fetch.c | |
parent | adc026dc209c4847c3f64c83a16d9aa614899737 (diff) | |
download | FreeBSD-src-3ce22a8bc5d1323c5a08611b3eb039b507d894b4.zip FreeBSD-src-3ce22a8bc5d1323c5a08611b3eb039b507d894b4.tar.gz |
Fix two bugs related to resumed transfers:
- if the dates didn't match, fetch would append the received file to the
existing file instead of replacing it.
- if the local file was complete and up-to-date, fetch would miscalculate
the expected size and report a failure instead of a success, because it
had no way of knowing that the server was actually resending the entire
file since the requested offset was invalid.
Diffstat (limited to 'usr.bin/fetch/fetch.c')
-rw-r--r-- | usr.bin/fetch/fetch.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index 556ec05..18e5569 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -258,6 +258,8 @@ fetch(char *URL, char *path) */ if (r_flag && !o_stdout && stat(path, &sb) != -1) url->offset = sb.st_size; + else + sb.st_size = 0; /* start the transfer */ if ((f = fetchXGet(url, &us, flags)) == NULL) { @@ -292,7 +294,7 @@ fetch(char *URL, char *path) if (o_stdout) { /* output to stdout */ of = stdout; - } else if (url->offset) { + } else if (sb.st_size) { /* resume mode, local file exists */ if (!F_flag && us.mtime && sb.st_mtime != us.mtime) { /* no match! have to refetch */ @@ -306,25 +308,29 @@ fetch(char *URL, char *path) goto signal; } else { us.size += url->offset; - } - if (us.size == sb.st_size) - /* nothing to do */ - goto success; - if (sb.st_size > us.size) { - /* local file too long! */ - warnx("%s: local file (%lld bytes) is longer " - "than remote file (%lld bytes)", - path, sb.st_size, us.size); - goto failure; - } - /* we got through, open local file in append mode */ - /* - * XXX there's a race condition here - the file we open is not - * necessarily the same as the one we stat()'ed earlier... - */ - if ((of = fopen(path, "a")) == NULL) { - warn("%s: open()", path); - goto failure; + if (us.size == sb.st_size) + /* nothing to do */ + goto success; + if (sb.st_size > us.size) { + /* local file too long! */ + warnx("%s: local file (%lld bytes) is longer " + "than remote file (%lld bytes)", + path, sb.st_size, us.size); + goto failure; + } + /* we got through, open local file and seek to offset */ + /* + * XXX there's a race condition here - the file we open is not + * necessarily the same as the one we stat()'ed earlier... + */ + if ((of = fopen(path, "a")) == NULL) { + warn("%s: fopen()", path); + goto failure; + } + if (fseek(of, url->offset, SEEK_SET) == -1) { + warn("%s: fseek()", path); + goto failure; + } } } if (m_flag && stat(path, &sb) != -1) { |