Mailinglist Archive: zypp-commit (149 mails)
< Previous | Next > |
[zypp-commit] r5380 - in /trunk/libzypp: cmake/modules/FindZsync.cmake devel/devel.dmacvicar/CMakeLists.txt devel/devel.dmacvicar/zsync.cc
- From: dmacvicar@xxxxxxxxxxxxxxxx
- Date: Sat, 14 Apr 2007 23:38:42 -0000
- Message-id: <20070414233842.8FF44236FA@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Sun Apr 15 01:38:42 2007
New Revision: 5380
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5380&view=rev
Log:
- test program that finds required download ranges using a old packages
file, and a .zsync file from a (remote) new one.
Added:
trunk/libzypp/cmake/modules/FindZsync.cmake
trunk/libzypp/devel/devel.dmacvicar/zsync.cc
Modified:
trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
Added: trunk/libzypp/cmake/modules/FindZsync.cmake
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/cmake/modules/FindZsync.cmake?rev=5380&view=auto
==============================================================================
--- trunk/libzypp/cmake/modules/FindZsync.cmake (added)
+++ trunk/libzypp/cmake/modules/FindZsync.cmake Sun Apr 15 01:38:42 2007
@@ -0,0 +1,34 @@
+
+if(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY)
+ # Already in cache, be silent
+ set(ZSYNC_FIND_QUIETLY TRUE)
+endif(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY)
+
+set(ZSYNC_LIBRARY)
+set(ZSYNC_INCLUDE_DIR)
+
+FIND_PATH(ZSYNC_INCLUDE_DIR zsync.h
+ /usr/include
+ /usr/local/include
+)
+
+FIND_LIBRARY(ZSYNC_LIBRARY NAMES zsync
+ PATHS
+ /usr/lib
+ /usr/local/lib
+)
+
+FIND_LIBRARY(RCKSUM_LIBRARY NAMES rcksum
+ PATHS
+ /usr/lib
+ /usr/local/lib
+)
+
+if(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY AND RCKSUM_LIBRARY)
+ MESSAGE( STATUS "zsync found: includes in ${ZSYNC_INCLUDE_DIR}, library in ${ZSYNC_LIBRARY}")
+ set(ZSYNC_FOUND TRUE)
+else(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY)
+ MESSAGE( STATUS "zsync not found")
+endif(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY AND RCKSUM_LIBRARY)
+
+MARK_AS_ADVANCED(ZSYNC_INCLUDE_DIR ZSYNC_LIBRARY RCKSUM_LIBRARY)
\ No newline at end of file
Modified: trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt?rev=5380&r1=5379&r2=5380&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt (original)
+++ trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt Sun Apr 15 01:38:42 2007
@@ -30,4 +30,12 @@
ADD_EXECUTABLE(yum-downloader YUMDownloader.cc YUMDownloader_tp.cc)
TARGET_LINK_LIBRARIES(yum-downloader zypp )
-TARGET_LINK_LIBRARIES(yum-downloader zypp2 )
\ No newline at end of file
+TARGET_LINK_LIBRARIES(yum-downloader zypp2 )
+
+FIND_PACKAGE(Zsync)
+IF(ZSYNC_FOUND)
+ ADD_EXECUTABLE(zsync zsync.cc)
+ TARGET_LINK_LIBRARIES(zsync ${ZSYNC_LIBRARY} ${RCKSUM_LIBRARY})
+ TARGET_LINK_LIBRARIES(zsync zypp )
+# TARGET_LINK_LIBRARIES(zsync zypp2 )
+ENDIF(ZSYNC_FOUND)
\ No newline at end of file
Added: trunk/libzypp/devel/devel.dmacvicar/zsync.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/zsync.cc?rev=5380&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/zsync.cc (added)
+++ trunk/libzypp/devel/devel.dmacvicar/zsync.cc Sun Apr 15 01:38:42 2007
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+extern "C" {
+#include <zsync.h>
+}
+#include "zypp/base/Exception.h"
+#include "zypp/base/Logger.h"
+#include "zypp/Pathname.h"
+#include "zypp/ExternalProgram.cc"
+//#include
+
+using namespace zypp;
+using namespace std;
+
+void read_seed_file(struct zsync_state* z, const Pathname &path )
+{
+ if (zsync_hint_decompress(z) && path.basename().size() > 3 && path.extension() == ".gz" )
+ {
+ FILE* f;
+ {
+ // ugh
+ char* cmd = (char *) malloc(6 + strlen(path.c_str())*2);
+
+ if (!cmd) return;
+
+ const char *fname = path.c_str();
+ strcpy(cmd,"zcat ");
+ {
+ int i,j;
+ for (i=0,j=5; fname[i]; i++)
+ {
+ if (!isalnum(fname[i])) cmd[j++] = '\\';
+ cmd[j++] = fname[i];
+ }
+ cmd[j] = 0;
+ }
+
+ //if (!no_progress) fprintf(stderr,"reading seed %s: ",cmd);
+ MIL << "Reading seed " << cmd << endl;
+ f = popen(cmd,"r");
+ free(cmd);
+ }
+
+ if (!f)
+ {
+ //perror("popen"); fprintf(stderr,"not using seed file %s\n",fname);
+ ZYPP_THROW(Exception("not using seed file"));
+ }
+ else
+ {
+ // 0 no progress
+ zsync_submit_source_file(z, f, 0);
+ if (pclose(f) != 0)
+ {
+ ZYPP_THROW(Exception("pclose"));
+ perror("close");
+ }
+ }
+ }
+ else
+ {
+ FILE* f = fopen(path.c_str(),"r");
+ MIL << "Reading seed " << path << endl;
+ if (!f) {
+ //perror("open"); fprintf(stderr,"not using seed file %s\n",fname);
+ ZYPP_THROW(Exception("open: " + path.asString()));
+ }
+ else
+ {
+ // 0 no progress
+ zsync_submit_source_file(z, f, 0);
+ if (fclose(f) != 0)
+ {
+ perror("close");
+ }
+ }
+ }
+ {
+ long long done,total;
+ zsync_progress(z, &done, &total);
+ MIL << "Read " << path << ". Target " << (100.0f * done)/total << " complete" << endl;
+ }
+}
+
+void figure_ranges(struct zsync_state* zs)
+{
+ //struct zsync_receiver* zr;
+ int num_ranges;
+ // it seems type is 1 for gz, 0 normal
+ off_t *ranges = zsync_needed_byte_ranges(zs, &num_ranges, 0);
+ int i=0;
+
+ MIL << "Need to get " << num_ranges << " ranges" << endl;
+
+ while ( i < 2*num_ranges )
+ {
+ int from = ranges[i];
+ MIL << "From: " << ranges[i] << " To: " << ranges[i+1] << endl;
+ i += 2;
+ }
+
+ free(ranges);
+}
+
+int main()
+{
+ Pathname root("/home/duncan/suse/metadata-diff");
+ struct zsync_state* zs;
+
+ FILE *f = fopen( (root+"/3/packages.zsync").c_str(), "r" );
+
+ if ((zs = zsync_begin(f)) == NULL)
+ {
+ exit(1);
+ }
+
+ if (fclose(f) != 0)
+ {
+ perror("fclose"); exit(2);
+ }
+
+ read_seed_file( zs, root + "1/packages" );
+ figure_ranges(zs);
+
+ zsync_end(zs);
+ return 0;
+}
\ No newline at end of file
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx
Date: Sun Apr 15 01:38:42 2007
New Revision: 5380
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5380&view=rev
Log:
- test program that finds required download ranges using a old packages
file, and a .zsync file from a (remote) new one.
Added:
trunk/libzypp/cmake/modules/FindZsync.cmake
trunk/libzypp/devel/devel.dmacvicar/zsync.cc
Modified:
trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
Added: trunk/libzypp/cmake/modules/FindZsync.cmake
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/cmake/modules/FindZsync.cmake?rev=5380&view=auto
==============================================================================
--- trunk/libzypp/cmake/modules/FindZsync.cmake (added)
+++ trunk/libzypp/cmake/modules/FindZsync.cmake Sun Apr 15 01:38:42 2007
@@ -0,0 +1,34 @@
+
+if(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY)
+ # Already in cache, be silent
+ set(ZSYNC_FIND_QUIETLY TRUE)
+endif(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY)
+
+set(ZSYNC_LIBRARY)
+set(ZSYNC_INCLUDE_DIR)
+
+FIND_PATH(ZSYNC_INCLUDE_DIR zsync.h
+ /usr/include
+ /usr/local/include
+)
+
+FIND_LIBRARY(ZSYNC_LIBRARY NAMES zsync
+ PATHS
+ /usr/lib
+ /usr/local/lib
+)
+
+FIND_LIBRARY(RCKSUM_LIBRARY NAMES rcksum
+ PATHS
+ /usr/lib
+ /usr/local/lib
+)
+
+if(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY AND RCKSUM_LIBRARY)
+ MESSAGE( STATUS "zsync found: includes in ${ZSYNC_INCLUDE_DIR}, library in ${ZSYNC_LIBRARY}")
+ set(ZSYNC_FOUND TRUE)
+else(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY)
+ MESSAGE( STATUS "zsync not found")
+endif(ZSYNC_INCLUDE_DIR AND ZSYNC_LIBRARY AND RCKSUM_LIBRARY)
+
+MARK_AS_ADVANCED(ZSYNC_INCLUDE_DIR ZSYNC_LIBRARY RCKSUM_LIBRARY)
\ No newline at end of file
Modified: trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt?rev=5380&r1=5379&r2=5380&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt (original)
+++ trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt Sun Apr 15 01:38:42 2007
@@ -30,4 +30,12 @@
ADD_EXECUTABLE(yum-downloader YUMDownloader.cc YUMDownloader_tp.cc)
TARGET_LINK_LIBRARIES(yum-downloader zypp )
-TARGET_LINK_LIBRARIES(yum-downloader zypp2 )
\ No newline at end of file
+TARGET_LINK_LIBRARIES(yum-downloader zypp2 )
+
+FIND_PACKAGE(Zsync)
+IF(ZSYNC_FOUND)
+ ADD_EXECUTABLE(zsync zsync.cc)
+ TARGET_LINK_LIBRARIES(zsync ${ZSYNC_LIBRARY} ${RCKSUM_LIBRARY})
+ TARGET_LINK_LIBRARIES(zsync zypp )
+# TARGET_LINK_LIBRARIES(zsync zypp2 )
+ENDIF(ZSYNC_FOUND)
\ No newline at end of file
Added: trunk/libzypp/devel/devel.dmacvicar/zsync.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/zsync.cc?rev=5380&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/zsync.cc (added)
+++ trunk/libzypp/devel/devel.dmacvicar/zsync.cc Sun Apr 15 01:38:42 2007
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+extern "C" {
+#include <zsync.h>
+}
+#include "zypp/base/Exception.h"
+#include "zypp/base/Logger.h"
+#include "zypp/Pathname.h"
+#include "zypp/ExternalProgram.cc"
+//#include
+
+using namespace zypp;
+using namespace std;
+
+void read_seed_file(struct zsync_state* z, const Pathname &path )
+{
+ if (zsync_hint_decompress(z) && path.basename().size() > 3 && path.extension() == ".gz" )
+ {
+ FILE* f;
+ {
+ // ugh
+ char* cmd = (char *) malloc(6 + strlen(path.c_str())*2);
+
+ if (!cmd) return;
+
+ const char *fname = path.c_str();
+ strcpy(cmd,"zcat ");
+ {
+ int i,j;
+ for (i=0,j=5; fname[i]; i++)
+ {
+ if (!isalnum(fname[i])) cmd[j++] = '\\';
+ cmd[j++] = fname[i];
+ }
+ cmd[j] = 0;
+ }
+
+ //if (!no_progress) fprintf(stderr,"reading seed %s: ",cmd);
+ MIL << "Reading seed " << cmd << endl;
+ f = popen(cmd,"r");
+ free(cmd);
+ }
+
+ if (!f)
+ {
+ //perror("popen"); fprintf(stderr,"not using seed file %s\n",fname);
+ ZYPP_THROW(Exception("not using seed file"));
+ }
+ else
+ {
+ // 0 no progress
+ zsync_submit_source_file(z, f, 0);
+ if (pclose(f) != 0)
+ {
+ ZYPP_THROW(Exception("pclose"));
+ perror("close");
+ }
+ }
+ }
+ else
+ {
+ FILE* f = fopen(path.c_str(),"r");
+ MIL << "Reading seed " << path << endl;
+ if (!f) {
+ //perror("open"); fprintf(stderr,"not using seed file %s\n",fname);
+ ZYPP_THROW(Exception("open: " + path.asString()));
+ }
+ else
+ {
+ // 0 no progress
+ zsync_submit_source_file(z, f, 0);
+ if (fclose(f) != 0)
+ {
+ perror("close");
+ }
+ }
+ }
+ {
+ long long done,total;
+ zsync_progress(z, &done, &total);
+ MIL << "Read " << path << ". Target " << (100.0f * done)/total << " complete" << endl;
+ }
+}
+
+void figure_ranges(struct zsync_state* zs)
+{
+ //struct zsync_receiver* zr;
+ int num_ranges;
+ // it seems type is 1 for gz, 0 normal
+ off_t *ranges = zsync_needed_byte_ranges(zs, &num_ranges, 0);
+ int i=0;
+
+ MIL << "Need to get " << num_ranges << " ranges" << endl;
+
+ while ( i < 2*num_ranges )
+ {
+ int from = ranges[i];
+ MIL << "From: " << ranges[i] << " To: " << ranges[i+1] << endl;
+ i += 2;
+ }
+
+ free(ranges);
+}
+
+int main()
+{
+ Pathname root("/home/duncan/suse/metadata-diff");
+ struct zsync_state* zs;
+
+ FILE *f = fopen( (root+"/3/packages.zsync").c_str(), "r" );
+
+ if ((zs = zsync_begin(f)) == NULL)
+ {
+ exit(1);
+ }
+
+ if (fclose(f) != 0)
+ {
+ perror("fclose"); exit(2);
+ }
+
+ read_seed_file( zs, root + "1/packages" );
+ figure_ranges(zs);
+
+ zsync_end(zs);
+ return 0;
+}
\ No newline at end of file
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx
< Previous | Next > |