diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-10-19 21:05:59 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-10-19 21:05:59 +0000 |
commit | a0c6ec97c97f372e7717be6f618f7b02b7aed6c5 (patch) | |
tree | 955c6476e40d746de60900c263155556bce91574 /usr.bin/fetch/fetch.c | |
parent | 4e94026a72ea98d174f08a42ad5b440c35bccbc8 (diff) | |
download | src-a0c6ec97c97f372e7717be6f618f7b02b7aed6c5.tar.gz src-a0c6ec97c97f372e7717be6f618f7b02b7aed6c5.zip |
Understand the difference between an empty file and a non-existent file.
This has been sitting in my tree for ages...
Notes
Notes:
svn path=/head/; revision=67326
Diffstat (limited to 'usr.bin/fetch/fetch.c')
-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 b33fb037850b..2004d8f4a590 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; |