1 This patch adds the --append option, which works like a "resume" mode in
2 an ftp client, appending new data onto the end of the files it updates.
4 --- orig/generator.c 2005-02-11 20:25:07
5 +++ generator.c 2005-02-11 20:26:31
6 @@ -40,6 +40,7 @@ extern int delete_during;
7 extern int update_only;
8 extern int opt_ignore_existing;
10 +extern int append_mode;
11 extern int make_backups;
12 extern int csum_length;
13 extern int ignore_times;
14 @@ -192,35 +193,42 @@ static void generate_and_send_sums(int f
17 sum_sizes_sqroot(&sum, len);
18 + write_sum_head(f_out, &sum);
20 + if (append_mode > 0 && f_copy < 0)
24 mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength);
28 - write_sum_head(f_out, &sum);
30 for (i = 0; i < sum.count; i++) {
31 int32 n1 = (int32)MIN(len, (OFF_T)sum.blength);
32 char *map = map_ptr(mapbuf, offset, n1);
33 - uint32 sum1 = get_checksum1(map, n1);
34 char sum2[SUM_LENGTH];
42 full_write(f_copy, map, n1);
43 + if (append_mode > 0)
47 + sum1 = get_checksum1(map, n1);
48 get_checksum2(map, n1, sum2);
52 "chunk[%.0f] offset=%.0f len=%ld sum1=%08lx\n",
53 - (double)i, (double)offset, (long)n1,
54 + (double)i, (double)offset - n1, (long)n1,
57 write_int(f_out, sum1);
58 write_buf(f_out, sum2, sum.s2length);
64 @@ -509,6 +517,9 @@ static void recv_generator(char *fname,
68 + if (append_mode && st.st_size > file->length)
71 if (!compare_dest && fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
73 else if (unchanged_file(fnamecmp, file, &st)) {
74 @@ -527,7 +538,7 @@ prepare_to_open:
76 if (dry_run || read_batch)
78 - if (whole_file > 0) {
79 + if (whole_file > 0 && !append_mode) {
83 @@ -664,6 +675,9 @@ void generate_files(int f_out, struct fi
84 csum_length = SUM_LENGTH;
85 only_existing = max_size = opt_ignore_existing = 0;
86 update_only = always_checksum = size_only = 0;
87 + make_backups = 0; /* avoid a duplicate backup in inplace mode */
88 + if (append_mode) /* resend w/o append mode */
89 + append_mode = -1; /* ... but only longer files */
93 --- orig/match.c 2005-01-17 23:11:45
94 +++ match.c 2005-02-11 20:26:31
95 @@ -23,6 +23,7 @@ extern int verbose;
97 extern int do_progress;
98 extern int checksum_seed;
99 +extern int append_mode;
101 int updating_basis_file;
103 @@ -336,6 +337,21 @@ void match_sums(int f, struct sum_struct
105 sum_init(checksum_seed);
109 + for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) {
110 + sum_update(map_ptr(buf, last_match, CHUNK_SIZE),
114 + if (last_match < s->flength) {
115 + int32 len = s->flength - last_match;
116 + sum_update(map_ptr(buf, last_match, len), len);
117 + last_match = s->flength;
122 if (len > 0 && s->count > 0) {
125 @@ -349,7 +365,7 @@ void match_sums(int f, struct sum_struct
128 /* by doing this in pieces we avoid too many seeks */
129 - for (j = CHUNK_SIZE; j < len; j += CHUNK_SIZE)
130 + for (j = last_match + CHUNK_SIZE; j < len; j += CHUNK_SIZE)
131 matched(f, s, buf, j, -2);
132 matched(f, s, buf, len, -1);
134 --- orig/options.c 2005-02-11 18:21:45
135 +++ options.c 2005-02-11 20:31:32
136 @@ -39,6 +39,7 @@ int make_backups = 0;
140 +int append_mode = 0;
141 int archive_mode = 0;
142 int keep_dirlinks = 0;
144 @@ -150,7 +151,7 @@ static int daemon_opt; /* sets am_daem
145 static int F_option_cnt = 0;
146 static int modify_window_set;
147 static int refused_verbose, refused_delete, refused_archive_part;
148 -static int refused_partial, refused_progress;
149 +static int refused_partial, refused_progress, refused_inplace;
150 static char *dest_option = NULL;
151 static char *max_size_arg;
152 static char partialdir_for_delayupdate[] = ".~tmp~";
153 @@ -260,6 +261,7 @@ void usage(enum logcode F)
154 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
155 rprintf(F," -u, --update skip files that are newer on the receiver\n");
156 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
157 + rprintf(F," --append append data onto shorter files\n");
158 rprintf(F," -d, --dirs transfer directories without recursing\n");
159 rprintf(F," -l, --links copy symlinks as symlinks\n");
160 rprintf(F," -L, --copy-links transform symlink into referent file/dir\n");
161 @@ -383,6 +385,7 @@ static struct poptOption long_options[]
162 {"links", 'l', POPT_ARG_NONE, &preserve_links, 0, 0, 0 },
163 {"copy-links", 'L', POPT_ARG_NONE, ©_links, 0, 0, 0 },
164 {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
165 + {"append", 0, POPT_ARG_VAL, &append_mode, 1, 0, 0 },
166 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
167 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
168 {"copy-unsafe-links", 0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
169 @@ -555,6 +558,8 @@ static void set_refuse_options(char *bp)
170 refused_partial = op->val;
171 else if (wildmatch("progress", op->longName))
172 refused_progress = op->val;
173 + else if (wildmatch("inplace", op->longName))
174 + refused_inplace = op->val;
178 @@ -1060,6 +1065,14 @@ int parse_arguments(int *argc, const cha
179 bwlimit_writemax = 512;
183 + if (refused_inplace) {
184 + create_refuse_error(refused_inplace);
190 if (delay_updates && !partial_dir)
191 partial_dir = partialdir_for_delayupdate;
193 @@ -1346,7 +1359,9 @@ void server_options(char **args,int *arg
194 if (opt_ignore_existing && am_sender)
195 args[ac++] = "--ignore-existing";
199 + args[ac++] = "--append";
201 args[ac++] = "--inplace";
204 --- orig/receiver.c 2005-02-11 10:53:14
205 +++ receiver.c 2005-02-11 20:26:32
206 @@ -44,6 +44,7 @@ extern int cleanup_got_literal;
207 extern int module_id;
208 extern int ignore_errors;
209 extern int orig_umask;
210 +extern int append_mode;
211 extern int keep_partial;
212 extern int checksum_seed;
214 @@ -164,6 +165,28 @@ static int receive_data(int f_in, char *
216 sum_init(checksum_seed);
220 + sum.flength = (OFF_T)sum.count * sum.blength;
222 + sum.flength -= sum.blength - sum.remainder;
223 + for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) {
224 + sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE),
228 + if (offset < sum.flength) {
229 + int32 len = sum.flength - offset;
230 + sum_update(map_ptr(mapbuf, offset, len), len);
231 + offset = sum.flength;
233 + if (fd != -1 && do_lseek(fd, offset, SEEK_SET) != offset) {
234 + rsyserr(FERROR, errno, "lseek failed on %s",
235 + full_fname(fname));
236 + exit_cleanup(RERR_FILEIO);
240 while ((i = recv_token(f_in, &data)) != 0) {
242 show_progress(offset, total_size);
243 @@ -325,6 +348,7 @@ int recv_files(int f_in, struct file_lis
244 send_msg(MSG_DONE, "", 0);
245 if (keep_partial && !partial_dir)
246 make_backups = 0; /* prevents double backup */
251 --- orig/rsync.yo 2005-02-11 10:53:15
252 +++ rsync.yo 2005-02-11 20:36:38
253 @@ -309,6 +309,7 @@ to the detailed description below for a
254 --suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
255 -u, --update skip files that are newer on the receiver
256 --inplace update destination files in-place
257 + --append append data onto shorter files
258 -d, --dirs transfer directories without recursing
259 -l, --links copy symlinks as symlinks
260 -L, --copy-links transform symlink into referent file/dir
261 @@ -553,6 +554,14 @@ should not use this option to update fil
262 rsync will be unable to update a file in-place that is not writable by the
265 +dit(bf(--append)) This causes rsync to update a file by appending data onto
266 +the end of the file, which presumes that the data that already exists on
267 +the receiving side is identical with the start of the file on the sending
268 +side. If that is not true, the file will fail the checksum check, and a
269 +normal bf(--inplace) update will correct the mismatch. Any file on the
270 +receiving side that is longer than a file on the sending side is skipped.
271 +Implies bf(--inplace).
273 dit(bf(-d, --dirs)) Tell the sending side to include any directories that
274 are encountered. Unlike bf(--recursive), a directory's contents are not copied
275 unless the directory was specified on the command-line as either "." or a
276 --- orig/sender.c 2005-02-03 02:04:20
277 +++ sender.c 2005-02-11 20:26:32
278 @@ -30,6 +30,7 @@ extern int protocol_version;
279 extern int updating_basis_file;
280 extern int make_backups;
282 +extern int append_mode;
283 extern struct stats stats;
286 @@ -62,6 +63,13 @@ static struct sum_struct *receive_sums(i
287 (double)s->count, (long)s->blength, (long)s->remainder);
291 + s->flength = (OFF_T)s->count * s->blength;
293 + s->flength -= s->blength - s->remainder;
300 @@ -127,6 +135,7 @@ void send_files(struct file_list *flist,
301 /* For inplace: redo phase turns off the backup
302 * flag so that we do a regular inplace send. */