summaryrefslogtreecommitdiff
path: root/rsync
Unidiff
Diffstat (limited to 'rsync') (more/less context) (ignore whitespace changes)
-rw-r--r--rsync/qrsync.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/rsync/qrsync.cpp b/rsync/qrsync.cpp
index fe5f1bc..a2dbafc 100644
--- a/rsync/qrsync.cpp
+++ b/rsync/qrsync.cpp
@@ -1,110 +1,115 @@
1#include "qrsync.h" 1#include "qrsync.h"
2#include <stdio.h> 2#include <stdio.h>
3extern "C" { 3extern "C" {
4#include "rsync.h" 4#include "rsync.h"
5} 5}
6#include <stdlib.h> 6#include <stdlib.h>
7 7
8/* OPIE */
9#include <opie2/odebug.h>
10using namespace Opie::Core;
11
12/* QT */
8#include <qfile.h> 13#include <qfile.h>
9 14
10static const char *rdiffNewFile = "/tmp/rdiff/result"; 15static const char *rdiffNewFile = "/tmp/rdiff/result";
11static size_t block_len = RS_DEFAULT_BLOCK_LEN; 16static size_t block_len = RS_DEFAULT_BLOCK_LEN;
12static size_t strong_len = RS_DEFAULT_STRONG_LEN; 17static size_t strong_len = RS_DEFAULT_STRONG_LEN;
13 18
14 19
15void QRsync::generateSignature( QString baseFile, QString sigFile ) 20void QRsync::generateSignature( QString baseFile, QString sigFile )
16{ 21{
17 22
18 if ( QFile::exists( baseFile ) ) { 23 if ( QFile::exists( baseFile ) ) {
19 FILE *basis_file, *sig_file; 24 FILE *basis_file, *sig_file;
20 rs_result result; 25 rs_result result;
21 26
22 basis_file = fopen( baseFile.latin1(), "rb" ); 27 basis_file = fopen( baseFile.latin1(), "rb" );
23 sig_file = fopen( sigFile.latin1(), "wb" ); 28 sig_file = fopen( sigFile.latin1(), "wb" );
24 29
25 result = rs_sig_file(basis_file, sig_file, block_len, strong_len, 0); 30 result = rs_sig_file(basis_file, sig_file, block_len, strong_len, 0);
26 31
27 fclose( basis_file ); 32 fclose( basis_file );
28 fclose( sig_file ); 33 fclose( sig_file );
29 if (result != RS_DONE) 34 if (result != RS_DONE)
30 printf("error in rdiffGenSig: %d", result ); 35 printf("error in rdiffGenSig: %d", result );
31 } 36 }
32} 37}
33 38
34 39
35void QRsync::generateDiff( QString baseFile, QString sigFile, QString deltaFile ) 40void QRsync::generateDiff( QString baseFile, QString sigFile, QString deltaFile )
36{ 41{
37 if ( QFile::exists( baseFile ) && QFile::exists( sigFile ) ) { 42 if ( QFile::exists( baseFile ) && QFile::exists( sigFile ) ) {
38 FILE *sig_file, *new_file, *delta_file; 43 FILE *sig_file, *new_file, *delta_file;
39 rs_result result; 44 rs_result result;
40 rs_signature_t *sumset; 45 rs_signature_t *sumset;
41 46
42 sig_file = fopen(sigFile.latin1(), "rb"); 47 sig_file = fopen(sigFile.latin1(), "rb");
43 new_file = fopen(baseFile.latin1(), "rb"); 48 new_file = fopen(baseFile.latin1(), "rb");
44 delta_file = fopen(deltaFile.latin1(), "wb"); 49 delta_file = fopen(deltaFile.latin1(), "wb");
45 50
46 result = rs_loadsig_file(sig_file, &sumset, 0); 51 result = rs_loadsig_file(sig_file, &sumset, 0);
47 if (result != RS_DONE) { 52 if (result != RS_DONE) {
48 qDebug( "rdiffGenDiff: loading of sig file failed, error=%d", result ); 53 odebug << "rdiffGenDiff: loading of sig file failed, error=" << result << "" << oendl;
49 } else { 54 } else {
50 result = rs_build_hash_table(sumset); 55 result = rs_build_hash_table(sumset);
51 if ( result != RS_DONE) { 56 if ( result != RS_DONE) {
52 qDebug( "rdiffGenDiff: building of hash table failed, error=%d", result ); 57 odebug << "rdiffGenDiff: building of hash table failed, error=" << result << "" << oendl;
53 } else { 58 } else {
54 result = rs_delta_file(sumset, new_file, delta_file, 0); 59 result = rs_delta_file(sumset, new_file, delta_file, 0);
55 if ( result != RS_DONE) { 60 if ( result != RS_DONE) {
56 qDebug( "rdiffGenDiff: writing of diff file failed, error=%d", result ); 61 odebug << "rdiffGenDiff: writing of diff file failed, error=" << result << "" << oendl;
57 } 62 }
58 } 63 }
59 } 64 }
60 65
61 if ( sumset ) 66 if ( sumset )
62 rs_free_sumset( sumset ); 67 rs_free_sumset( sumset );
63 fclose( new_file ); 68 fclose( new_file );
64 fclose( delta_file ); 69 fclose( delta_file );
65 fclose( sig_file ); 70 fclose( sig_file );
66 71
67 } 72 }
68} 73}
69 74
70void QRsync::applyDiff( QString baseFile, QString deltaFile ) 75void QRsync::applyDiff( QString baseFile, QString deltaFile )
71{ 76{
72 if ( QFile::exists( baseFile ) && QFile::exists( deltaFile ) ) { 77 if ( QFile::exists( baseFile ) && QFile::exists( deltaFile ) ) {
73 FILE *basis_file, *delta_file, *new_file; 78 FILE *basis_file, *delta_file, *new_file;
74 rs_result result; 79 rs_result result;
75 80
76 basis_file = fopen(baseFile.latin1(), "rb"); 81 basis_file = fopen(baseFile.latin1(), "rb");
77 delta_file = fopen(deltaFile.latin1(), "rb"); 82 delta_file = fopen(deltaFile.latin1(), "rb");
78#ifdef Q_WS_WIN 83#ifdef Q_WS_WIN
79 new_file = fopen( (baseFile + ".new").latin1(), "wb" ); 84 new_file = fopen( (baseFile + ".new").latin1(), "wb" );
80#else 85#else
81 new_file = fopen(rdiffNewFile, "wb"); 86 new_file = fopen(rdiffNewFile, "wb");
82 #endif 87 #endif
83 88
84 result = rs_patch_file(basis_file, delta_file, new_file, 0); 89 result = rs_patch_file(basis_file, delta_file, new_file, 0);
85 90
86 fclose( basis_file ); 91 fclose( basis_file );
87 fclose( delta_file ); 92 fclose( delta_file );
88 fclose( new_file ); 93 fclose( new_file );
89 94
90 if (result != RS_DONE) { 95 if (result != RS_DONE) {
91 qDebug( "rdiffApplyDiff failed with result %d", result ); 96 odebug << "rdiffApplyDiff failed with result " << result << "" << oendl;
92 return; 97 return;
93 } 98 }
94 99
95 100
96 #ifdef Q_WS_WIN 101 #ifdef Q_WS_WIN
97 QDir dir; 102 QDir dir;
98 QFile backup = baseFile + "~"; 103 QFile backup = baseFile + "~";
99 dir.rename( baseFile, backup ); 104 dir.rename( baseFile, backup );
100 dir.rename( (baseFile + ".new"), baseFile ); 105 dir.rename( (baseFile + ".new"), baseFile );
101 dir.remove( backup ); 106 dir.remove( backup );
102#else 107#else
103 QString cmd = "mv "; 108 QString cmd = "mv ";
104 cmd += rdiffNewFile; 109 cmd += rdiffNewFile;
105 cmd += " " + baseFile; 110 cmd += " " + baseFile;
106 system( cmd.latin1() ); 111 system( cmd.latin1() );
107#endif 112#endif
108 } 113 }
109 114
110} 115}