7 #include "zypp/base/Exception.h"
8 #include "zypp/base/Logger.h"
9 #include "zypp/Pathname.h"
10 #include "zypp/ExternalProgram.cc"
16 void read_seed_file(struct zsync_state* z, const Pathname &path )
18 if (zsync_hint_decompress(z) && path.basename().size() > 3 && path.extension() == ".gz" )
23 char* cmd = (char *) malloc(6 + strlen(path.c_str())*2);
27 const char *fname = path.c_str();
31 for (i=0,j=5; fname[i]; i++)
33 if (!isalnum(fname[i])) cmd[j++] = '\\';
39 //if (!no_progress) fprintf(stderr,"reading seed %s: ",cmd);
40 MIL << "Reading seed " << cmd << endl;
47 //perror("popen"); fprintf(stderr,"not using seed file %s\n",fname);
48 ZYPP_THROW(Exception("not using seed file"));
53 zsync_submit_source_file(z, f, 0);
56 ZYPP_THROW(Exception("pclose"));
63 FILE* f = fopen(path.c_str(),"r");
64 MIL << "Reading seed " << path << endl;
66 //perror("open"); fprintf(stderr,"not using seed file %s\n",fname);
67 ZYPP_THROW(Exception("open: " + path.asString()));
72 zsync_submit_source_file(z, f, 0);
81 zsync_progress(z, &done, &total);
82 MIL << "Read " << path << ". Target " << (100.0f * done)/total << " complete" << endl;
86 void figure_ranges(struct zsync_state* zs)
88 //struct zsync_receiver* zr;
90 // it seems type is 1 for gz, 0 normal
91 off_t *ranges = zsync_needed_byte_ranges(zs, &num_ranges, 0);
94 MIL << "Need to get " << num_ranges << " ranges" << endl;
96 while ( i < 2*num_ranges )
99 MIL << "From: " << ranges[i] << " To: " << ranges[i+1] << endl;
108 Pathname root("/home/duncan/suse/metadata-diff");
109 struct zsync_state* zs;
111 FILE *f = fopen( (root+"/3/packages.zsync").c_str(), "r" );
113 if ((zs = zsync_begin(f)) == NULL)
120 perror("fclose"); exit(2);
123 read_seed_file( zs, root + "1/packages" );