Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Seed file reading optimisations.

Stop reading seed files if target is complete.
Also deduplicate seed files.
Optimisations suggested by Jan Varho.
  • Loading branch information...
commit 32ee703d2818a07884cc040b2967c39220eb56e3 1 parent 1d1364b
Colin Phipps authored
Showing with 22 additions and 8 deletions.
  1. +1 −0  c/NEWS
  2. +2 −2 c/README
  3. +19 −6 c/client.c
View
1  c/NEWS
@@ -2,6 +2,7 @@ Changes in 0.6.2
- fix for using zsync client on files >2GB on 32bit systems.
- fix redirect handling.
- improve some edge cases dealing with unusual seed data patterns.
+- optimise by stopping reading seed files if target file is complete.
- fix infinite loop in zsyncmake when given a truncated (invalid) .gz
- fix --disable-profile to configure.
View
4 c/README
@@ -138,6 +138,6 @@ compile farm for testing portability.
Also, thanks to Érsek László, James Montgomerie, James Antill,
saul@alien-science.org, Kent Mein, Marc Lehmann, Robert Lemmen, Mark Adler,
Ricardo Correia, Karl Kalleberg, Michael Stone, Richard Lucassen, Duncan
-Mac-Vicar, Jari Aalto and Marcin Mirosław for useful feedback and bug reports
-for previous versions.
+Mac-Vicar, Jari Aalto, Marcin Mirosław and Jan Varho for useful feedback and
+bug reports for previous versions.
View
25 c/client.c
@@ -543,14 +543,10 @@ int main(int argc, char **argv) {
*target file */
int i;
- /* Try any seed files supplied by the command line */
- for (i = 0; i < nseedfiles; i++) {
- read_seed_file(zs, seedfiles[i]);
- }
/* If the target file already exists, we're probably updating that file
* - so it's a seed file */
if (!access(filename, R_OK)) {
- read_seed_file(zs, filename);
+ seedfiles = append_ptrlist(&nseedfiles, seedfiles, filename);
}
/* If the .part file exists, it's probably an interrupted earlier
* effort; a normal HTTP client would 'resume' from where it got to,
@@ -558,9 +554,26 @@ int main(int argc, char **argv) {
* current version on the remote) and doesn't need to, because we can
* treat it like any other local source of data. Use it now. */
if (!access(temp_file, R_OK)) {
- read_seed_file(zs, temp_file);
+ seedfiles = append_ptrlist(&nseedfiles, seedfiles, temp_file);
}
+ /* Try any seed files supplied by the command line */
+ for (i = 0; i < nseedfiles; i++) {
+ int dup = 0, j;
+
+ /* And stop reading seed files once the target is complete. */
+ if (zsync_status(zs) >= 2) break;
+
+ /* Skip dups automatically, to save the person running the program
+ * having to worry about this stuff. */
+ for (j = 0; j < i; j++) {
+ if (!strcmp(seedfiles[i],seedfiles[j])) dup = 1;
+ }
+
+ /* And now, if not a duplicate, read it */
+ if (!dup)
+ read_seed_file(zs, seedfiles[i]);
+ }
/* Show how far that got us */
zsync_progress(zs, &local_used, NULL);
Please sign in to comment.
Something went wrong with that request. Please try again.