diff options
author | des <des@FreeBSD.org> | 2000-10-19 21:05:59 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-10-19 21:05:59 +0000 |
commit | 1763356b8331c5c743fd21627ed985a57c2b0b99 (patch) | |
tree | a25921486a91b68654a706877355f41c2e5147b9 /usr.bin/fetch | |
parent | eebf14cc044079991a47346a9d8e22f0df83cbac (diff) | |
download | FreeBSD-src-1763356b8331c5c743fd21627ed985a57c2b0b99.zip FreeBSD-src-1763356b8331c5c743fd21627ed985a57c2b0b99.tar.gz |
Understand the difference between an empty file and a non-existent file.
This has been sitting in my tree for ages...
Diffstat (limited to 'usr.bin/fetch')
-rw-r--r-- | usr.bin/fetch/fetch.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index b33fb03..2004d8f 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; |