1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
Description: changes to client.c and http.c in the Ubuntu packaging
- client.c, http.c:
+ Add an offset field ("O"), wanted for apt-zsync because we want to
step past the first members in the .deb archive
- client.c:
+ Print progress even if output is not a tty. This makes it
possible to gather statistics for an experimental apt-get
method.
- http.c:
+ use off_t instead of size_t where appropriate, for 64-bit cleanness
--- a/client.c
+++ b/client.c
@@ -446,6 +446,9 @@ static int set_mtime(char* filename, tim
/****************************************************************************
*
* Main program */
+
+extern long global_offset;
+
int main(int argc, char **argv) {
struct zsync_state *zs;
char *temp_file = NULL;
@@ -460,7 +463,7 @@ int main(int argc, char **argv) {
{ /* Option parsing */
int opt;
- while ((opt = getopt(argc, argv, "A:k:o:i:Vsqu:")) != -1) {
+ while ((opt = getopt(argc, argv, "A:k:o:O:i:Vsqu:")) != -1) {
switch (opt) {
case 'A': /* Authentication options for remote server */
{ /* Scan string as hostname=username:password */
@@ -487,6 +490,10 @@ int main(int argc, char **argv) {
free(filename);
filename = strdup(optarg);
break;
+ case 'O':
+ global_offset = atol(optarg);
+ if (global_offset%2) fprintf(stderr, "Warning: Odd offset defined\n");
+ break;
case 'i':
seedfiles = append_ptrlist(&nseedfiles, seedfiles, optarg);
break;
@@ -519,8 +526,9 @@ int main(int argc, char **argv) {
}
/* No progress display except on terminal */
- if (!isatty(0))
- no_progress = 1;
+ // Ubuntu change: print progress even if output is not a tty.
+ //if (!isatty(0))
+ // no_progress = 1;
{ /* Get proxy setting from the environment */
char *pr = getenv("http_proxy");
--- a/http.c
+++ b/http.c
@@ -44,6 +44,8 @@
#include "progress.h"
#include "format_string.h"
+long global_offset = 0;
+
/* socket = connect_to(host, service/port)
* Establishes a TCP connection to the named host and port (which can be
* supplied as a service name from /etc/services. Returns the socket handle, or
@@ -283,7 +285,7 @@ FILE *http_get(const char *orig_url, cha
if (http_date_string(st.st_mtime, buf, sizeof(buf)) != NULL)
snprintf(ifrange, sizeof(ifrange),
"If-Unmodified-Since: %s\r\nRange: bytes=" OFF_T_PF
- "-\r\n", buf, st.st_size);
+ "-\r\n", buf, st.st_size+global_offset);
}
else if (errno == ENOENT && stat(tfname, &st) == 0) {
/* Else, if we have a complete possibly-old version, so only transfer
@@ -770,7 +772,8 @@ static void range_fetch_getmore(struct r
/* Append to the request */
snprintf(request + l, sizeof(request) - l, OFF_T_PF "-" OFF_T_PF "%s",
- rf->ranges_todo[2 * i], rf->ranges_todo[2 * i + 1],
+ rf->ranges_todo[2 * i] + global_offset,
+ rf->ranges_todo[2 * i + 1] + global_offset,
lastrange ? "" : ",");
/* And record that we have sent this one */
@@ -901,8 +904,11 @@ int range_fetch_read_http_headers(struct
* range and set our state appropriately */
off_t from, to;
sscanf(p, "bytes " OFF_T_PF "-" OFF_T_PF "/", &from, &to);
+ from -= global_offset;
+ to -= global_offset;
if (from <= to) {
- rf->block_left = to + 1 - from;
+ if (global_offset && to%2) rf->block_left = to - from;
+ else rf->block_left = to + 1 - from;
rf->offset = from;
}
@@ -1088,7 +1094,7 @@ int get_range_block(struct range_fetch *
sscanf(buf,
"content-range: bytes " OFF_T_PF "-" OFF_T_PF "/",
&from, &to)) {
- rf->offset = from;
+ rf->offset = from - global_offset;
rf->block_left = to - from + 1;
gotr = 1;
}
|