Commit | Line | Data |
---|---|---|
2c0d3742 WD |
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. | |
3 | ||
a5e0f697 | 4 | --- orig/generator.c 2005-02-20 22:13:19 |
45f1b149 | 5 | +++ generator.c 2005-02-15 19:31:13 |
699c8be0 | 6 | @@ -46,6 +46,7 @@ extern int remove_sent_files; |
2c0d3742 WD |
7 | extern int update_only; |
8 | extern int opt_ignore_existing; | |
9 | extern int inplace; | |
10 | +extern int append_mode; | |
11 | extern int make_backups; | |
12 | extern int csum_length; | |
13 | extern int ignore_times; | |
699c8be0 | 14 | @@ -243,35 +244,42 @@ static void generate_and_send_sums(int f |
2c0d3742 WD |
15 | OFF_T offset = 0; |
16 | ||
17 | sum_sizes_sqroot(&sum, len); | |
18 | + write_sum_head(f_out, &sum); | |
19 | + | |
20 | + if (append_mode > 0 && f_copy < 0) | |
21 | + return; | |
22 | ||
23 | if (len > 0) | |
24 | mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength); | |
25 | else | |
26 | mapbuf = NULL; | |
27 | ||
28 | - write_sum_head(f_out, &sum); | |
29 | - | |
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]; | |
35 | + uint32 sum1; | |
36 | + | |
37 | + len -= n1; | |
38 | + offset += n1; | |
39 | ||
40 | - if (f_copy >= 0) | |
41 | + if (f_copy >= 0) { | |
42 | full_write(f_copy, map, n1); | |
43 | + if (append_mode > 0) | |
44 | + continue; | |
45 | + } | |
46 | ||
47 | + sum1 = get_checksum1(map, n1); | |
48 | get_checksum2(map, n1, sum2); | |
49 | ||
50 | if (verbose > 3) { | |
51 | rprintf(FINFO, | |
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, | |
55 | (unsigned long)sum1); | |
56 | } | |
57 | write_int(f_out, sum1); | |
58 | write_buf(f_out, sum2, sum.s2length); | |
59 | - len -= n1; | |
60 | - offset += n1; | |
61 | } | |
62 | ||
63 | if (mapbuf) | |
699c8be0 | 64 | @@ -731,6 +739,9 @@ static void recv_generator(char *fname, |
2c0d3742 WD |
65 | return; |
66 | } | |
67 | ||
68 | + if (append_mode && st.st_size > file->length) | |
69 | + return; | |
70 | + | |
71 | if (!compare_dest && fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) | |
72 | ; | |
45f1b149 | 73 | else if (fnamecmp_type == FNAMECMP_FUZZY) |
699c8be0 | 74 | @@ -757,7 +768,7 @@ prepare_to_open: |
2c0d3742 WD |
75 | |
76 | if (dry_run || read_batch) | |
77 | goto notify_others; | |
78 | - if (whole_file > 0) { | |
79 | + if (whole_file > 0 && !append_mode) { | |
45f1b149 WD |
80 | if (statret == 0) |
81 | statret = 1; | |
2c0d3742 | 82 | goto notify_others; |
699c8be0 | 83 | @@ -923,6 +934,9 @@ void generate_files(int f_out, struct fi |
2c0d3742 WD |
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 */ | |
90 | ignore_times = 1; | |
91 | ||
92 | if (verbose > 2) | |
45f1b149 | 93 | --- orig/match.c 2005-02-15 19:27:04 |
2c0d3742 WD |
94 | +++ match.c 2005-02-11 20:26:31 |
95 | @@ -23,6 +23,7 @@ extern int verbose; | |
96 | extern int am_server; | |
97 | extern int do_progress; | |
98 | extern int checksum_seed; | |
99 | +extern int append_mode; | |
100 | ||
101 | int updating_basis_file; | |
102 | ||
45f1b149 | 103 | @@ -334,6 +335,21 @@ void match_sums(int f, struct sum_struct |
2c0d3742 WD |
104 | |
105 | sum_init(checksum_seed); | |
106 | ||
107 | + if (append_mode) { | |
108 | + OFF_T j = 0; | |
109 | + for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) { | |
110 | + sum_update(map_ptr(buf, last_match, CHUNK_SIZE), | |
111 | + CHUNK_SIZE); | |
112 | + last_match = j; | |
113 | + } | |
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; | |
118 | + } | |
119 | + s->count = 0; | |
120 | + } | |
121 | + | |
122 | if (len > 0 && s->count > 0) { | |
123 | build_hash_table(s); | |
124 | ||
45f1b149 | 125 | @@ -347,7 +363,7 @@ void match_sums(int f, struct sum_struct |
2c0d3742 WD |
126 | } else { |
127 | OFF_T j; | |
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); | |
133 | } | |
699c8be0 | 134 | --- orig/options.c 2005-02-20 01:12:42 |
4e75164f | 135 | +++ options.c 2005-02-16 15:36:40 |
2c0d3742 WD |
136 | @@ -39,6 +39,7 @@ int make_backups = 0; |
137 | **/ | |
138 | int whole_file = -1; | |
139 | ||
140 | +int append_mode = 0; | |
141 | int archive_mode = 0; | |
142 | int keep_dirlinks = 0; | |
143 | int copy_links = 0; | |
699c8be0 | 144 | @@ -158,6 +159,7 @@ static int F_option_cnt = 0; |
2c0d3742 | 145 | static int modify_window_set; |
efd0f7d1 | 146 | static int refused_delete, refused_archive_part; |
4e75164f WD |
147 | static int refused_partial, refused_progress, refused_delete_before; |
148 | +static int refused_inplace; | |
2c0d3742 WD |
149 | static char *dest_option = NULL; |
150 | static char *max_size_arg; | |
151 | static char partialdir_for_delayupdate[] = ".~tmp~"; | |
699c8be0 | 152 | @@ -267,6 +269,7 @@ void usage(enum logcode F) |
2c0d3742 WD |
153 | rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX); |
154 | rprintf(F," -u, --update skip files that are newer on the receiver\n"); | |
155 | rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n"); | |
156 | + rprintf(F," --append append data onto shorter files\n"); | |
157 | rprintf(F," -d, --dirs transfer directories without recursing\n"); | |
158 | rprintf(F," -l, --links copy symlinks as symlinks\n"); | |
159 | rprintf(F," -L, --copy-links transform symlink into referent file/dir\n"); | |
699c8be0 | 160 | @@ -394,6 +397,7 @@ static struct poptOption long_options[] |
2c0d3742 WD |
161 | {"links", 'l', POPT_ARG_NONE, &preserve_links, 0, 0, 0 }, |
162 | {"copy-links", 'L', POPT_ARG_NONE, ©_links, 0, 0, 0 }, | |
163 | {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 }, | |
164 | + {"append", 0, POPT_ARG_VAL, &append_mode, 1, 0, 0 }, | |
165 | {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 }, | |
166 | {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 }, | |
45f1b149 | 167 | {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 }, |
699c8be0 | 168 | @@ -566,6 +570,8 @@ static void set_refuse_options(char *bp) |
2c0d3742 WD |
169 | refused_partial = op->val; |
170 | else if (wildmatch("progress", op->longName)) | |
171 | refused_progress = op->val; | |
172 | + else if (wildmatch("inplace", op->longName)) | |
173 | + refused_inplace = op->val; | |
174 | break; | |
175 | } | |
176 | if (!is_wild) | |
699c8be0 | 177 | @@ -1114,6 +1120,14 @@ int parse_arguments(int *argc, const cha |
2c0d3742 WD |
178 | bwlimit_writemax = 512; |
179 | } | |
180 | ||
181 | + if (append_mode) { | |
182 | + if (refused_inplace) { | |
183 | + create_refuse_error(refused_inplace); | |
184 | + return 0; | |
185 | + } | |
186 | + inplace = 1; | |
187 | + } | |
188 | + | |
189 | if (delay_updates && !partial_dir) | |
190 | partial_dir = partialdir_for_delayupdate; | |
191 | ||
699c8be0 | 192 | @@ -1411,7 +1425,9 @@ void server_options(char **args,int *arg |
2c0d3742 WD |
193 | if (opt_ignore_existing && am_sender) |
194 | args[ac++] = "--ignore-existing"; | |
195 | ||
196 | - if (inplace) | |
197 | + if (append_mode) | |
198 | + args[ac++] = "--append"; | |
199 | + else if (inplace) | |
200 | args[ac++] = "--inplace"; | |
201 | ||
202 | if (tmpdir) { | |
a5e0f697 | 203 | --- orig/receiver.c 2005-02-20 20:55:51 |
2c0d3742 | 204 | +++ receiver.c 2005-02-11 20:26:32 |
699c8be0 | 205 | @@ -45,6 +45,7 @@ extern int remove_sent_files; |
2c0d3742 WD |
206 | extern int module_id; |
207 | extern int ignore_errors; | |
208 | extern int orig_umask; | |
209 | +extern int append_mode; | |
210 | extern int keep_partial; | |
211 | extern int checksum_seed; | |
212 | extern int inplace; | |
a5e0f697 | 213 | @@ -233,6 +234,28 @@ static int receive_data(int f_in, char * |
2c0d3742 WD |
214 | |
215 | sum_init(checksum_seed); | |
216 | ||
217 | + if (append_mode) { | |
218 | + OFF_T j; | |
219 | + sum.flength = (OFF_T)sum.count * sum.blength; | |
220 | + if (sum.remainder) | |
221 | + sum.flength -= sum.blength - sum.remainder; | |
222 | + for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) { | |
223 | + sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE), | |
224 | + CHUNK_SIZE); | |
225 | + offset = j; | |
226 | + } | |
227 | + if (offset < sum.flength) { | |
228 | + int32 len = sum.flength - offset; | |
229 | + sum_update(map_ptr(mapbuf, offset, len), len); | |
230 | + offset = sum.flength; | |
231 | + } | |
232 | + if (fd != -1 && do_lseek(fd, offset, SEEK_SET) != offset) { | |
233 | + rsyserr(FERROR, errno, "lseek failed on %s", | |
234 | + full_fname(fname)); | |
235 | + exit_cleanup(RERR_FILEIO); | |
236 | + } | |
237 | + } | |
238 | + | |
239 | while ((i = recv_token(f_in, &data)) != 0) { | |
240 | if (do_progress) | |
241 | show_progress(offset, total_size); | |
a5e0f697 | 242 | @@ -422,6 +445,7 @@ int recv_files(int f_in, struct file_lis |
2c0d3742 WD |
243 | send_msg(MSG_DONE, "", 0); |
244 | if (keep_partial && !partial_dir) | |
245 | make_backups = 0; /* prevents double backup */ | |
246 | + append_mode = 0; | |
247 | continue; | |
248 | } | |
249 | ||
699c8be0 | 250 | --- orig/rsync.yo 2005-02-20 01:12:43 |
2c0d3742 WD |
251 | +++ rsync.yo 2005-02-11 20:36:38 |
252 | @@ -309,6 +309,7 @@ to the detailed description below for a | |
253 | --suffix=SUFFIX backup suffix (default ~ w/o --backup-dir) | |
254 | -u, --update skip files that are newer on the receiver | |
255 | --inplace update destination files in-place | |
256 | + --append append data onto shorter files | |
257 | -d, --dirs transfer directories without recursing | |
258 | -l, --links copy symlinks as symlinks | |
259 | -L, --copy-links transform symlink into referent file/dir | |
699c8be0 | 260 | @@ -565,6 +566,14 @@ should not use this option to update fil |
2c0d3742 WD |
261 | rsync will be unable to update a file in-place that is not writable by the |
262 | receiving user. | |
263 | ||
264 | +dit(bf(--append)) This causes rsync to update a file by appending data onto | |
265 | +the end of the file, which presumes that the data that already exists on | |
266 | +the receiving side is identical with the start of the file on the sending | |
267 | +side. If that is not true, the file will fail the checksum check, and a | |
268 | +normal bf(--inplace) update will correct the mismatch. Any file on the | |
269 | +receiving side that is longer than a file on the sending side is skipped. | |
270 | +Implies bf(--inplace). | |
271 | + | |
272 | dit(bf(-d, --dirs)) Tell the sending side to include any directories that | |
273 | are encountered. Unlike bf(--recursive), a directory's contents are not copied | |
274 | unless the directory was specified on the command-line as either "." or a | |
699c8be0 | 275 | --- orig/sender.c 2005-02-20 01:12:43 |
1d15f8d9 WD |
276 | +++ sender.c 2005-02-20 00:17:01 |
277 | @@ -28,6 +28,7 @@ extern int log_format_has_i; | |
278 | extern int daemon_log_format_has_i; | |
279 | extern int csum_length; | |
280 | extern int io_error; | |
2c0d3742 | 281 | +extern int append_mode; |
1d15f8d9 | 282 | extern int protocol_version; |
699c8be0 | 283 | extern int remove_sent_files; |
1d15f8d9 | 284 | extern int updating_basis_file; |
699c8be0 | 285 | @@ -67,6 +68,13 @@ static struct sum_struct *receive_sums(i |
2c0d3742 WD |
286 | (double)s->count, (long)s->blength, (long)s->remainder); |
287 | } | |
288 | ||
289 | + if (append_mode) { | |
290 | + s->flength = (OFF_T)s->count * s->blength; | |
291 | + if (s->remainder) | |
292 | + s->flength -= s->blength - s->remainder; | |
293 | + return s; | |
294 | + } | |
295 | + | |
296 | if (s->count == 0) | |
297 | return(s); | |
298 | ||
699c8be0 | 299 | @@ -161,6 +169,7 @@ void send_files(struct file_list *flist, |
2c0d3742 WD |
300 | /* For inplace: redo phase turns off the backup |
301 | * flag so that we do a regular inplace send. */ | |
302 | make_backups = 0; | |
303 | + append_mode = 0; | |
304 | continue; | |
305 | } | |
306 | break; |