Updated to apply cleanly.
[rsync/rsync-patches.git] / only-write-batch.diff
CommitLineData
541bc14e
WD
1--- orig/batch.c 2005-03-27 05:13:14
2+++ batch.c 2005-03-27 05:14:42
3@@ -139,7 +139,7 @@ static void write_filter_rules(int fd)
4 * (hopefully) work. */
5 void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
6 {
7- int fd, i;
8+ int fd, i, len;
9 char *p, filename[MAXPATHLEN];
10
11 stringjoin(filename, sizeof filename,
12@@ -175,11 +175,12 @@ void write_batch_shell_file(int argc, ch
13 continue;
14 }
15 write(fd, " ", 1);
16- if (strncmp(p, "--write-batch", 13) == 0) {
17+ if (strncmp(p, "--write-batch", len = 13) == 0
18+ || strncmp(p, "--only-write-batch", len = 18) == 0) {
19 write(fd, "--read-batch", 12);
20- if (p[13] == '=') {
21+ if (p[len] == '=') {
22 write(fd, "=", 1);
23- write_arg(fd, p + 14);
24+ write_arg(fd, p + len + 1);
25 }
26 } else
27 write_arg(fd, p);
e621c041 28--- orig/generator.c 2005-03-29 01:05:12
541bc14e
WD
29+++ generator.c 2005-03-24 07:07:12
30@@ -25,6 +25,7 @@
31
32 extern int verbose;
33 extern int dry_run;
34+extern int do_xfers;
35 extern int log_format_has_i;
36 extern int log_format_has_o_or_i;
37 extern int daemon_log_format_has_i;
e621c041 38@@ -1001,7 +1002,7 @@ prepare_to_open:
541bc14e
WD
39 statret = 0;
40 }
41
42- if (dry_run || read_batch || whole_file)
43+ if (!do_xfers || read_batch || whole_file)
44 goto notify_others;
45
46 if (fuzzy_basis) {
e621c041 47@@ -1073,7 +1074,7 @@ notify_others:
541bc14e
WD
48 fuzzy_file ? fuzzy_file->basename : NULL);
49 }
50
51- if (dry_run) {
52+ if (!do_xfers) {
53 if (preserve_hard_links && file->link_u.links)
54 hard_link_cluster(file, ndx, itemizing, code);
55 return;
e621c041 56@@ -1121,9 +1122,9 @@ void generate_files(int f_out, struct fi
541bc14e
WD
57 maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
58 code = daemon_log_format_has_i ? 0 : FLOG;
59 } else if (am_daemon) {
60- itemizing = daemon_log_format_has_i && !dry_run;
61+ itemizing = daemon_log_format_has_i && do_xfers;
62 maybe_PERMS_REPORT = PERMS_REPORT;
63- code = itemizing || dry_run ? FCLIENT : FINFO;
64+ code = itemizing || !do_xfers ? FCLIENT : FINFO;
65 } else if (!am_server) {
66 itemizing = log_format_has_i;
67 maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
68--- orig/main.c 2005-03-16 02:19:30
69+++ main.c 2005-03-24 07:07:12
70@@ -168,7 +168,7 @@ static void report(int f)
71 stats.flist_buildtime = read_longint(f);
72 stats.flist_xfertime = read_longint(f);
73 }
74- } else if (write_batch) {
75+ } else if (write_batch && !am_server) {
76 /* The --read-batch process is going to be a client
77 * receiver, so we need to give it the stats. */
78 write_longint(batch_fd, total_read);
79@@ -583,7 +583,7 @@ static int do_recv(int f_in,int f_out,st
80
81 am_generator = 1;
82 close_multiplexing_in();
83- if (write_batch)
84+ if (write_batch && !am_server)
85 stop_write_batch();
86
87 close(error_pipe[1]);
88@@ -756,7 +756,7 @@ int client_run(int f_in, int f_out, pid_
89 if (filesfrom_host)
90 filesfrom_fd = f_in;
91
92- if (write_batch)
93+ if (write_batch && !am_server)
94 start_write_batch(f_out);
95 flist = send_file_list(f_out, argc, argv);
96 set_msg_fd_in(-1);
97@@ -793,7 +793,7 @@ int client_run(int f_in, int f_out, pid_
98 filesfrom_fd = -1;
99 }
100
101- if (write_batch)
102+ if (write_batch && !am_server)
103 start_write_batch(f_in);
104 flist = recv_file_list(f_in);
105 if (!flist || flist->count == 0) {
106@@ -1111,7 +1111,7 @@ int main(int argc,char *argv[])
107
108 init_flist();
109
110- if (write_batch || read_batch) {
111+ if ((write_batch || read_batch) && !am_server) {
112 if (write_batch)
113 write_batch_shell_file(orig_argc, orig_argv, argc);
114
115@@ -1130,6 +1130,8 @@ int main(int argc,char *argv[])
116 if (read_batch)
117 read_stream_flags(batch_fd);
118 }
119+ if (write_batch < 0)
120+ dry_run = 1;
121
122 if (am_daemon && !am_server)
123 return daemon_main();
e621c041 124--- orig/options.c 2005-03-28 20:56:55
541bc14e
WD
125+++ options.c 2005-03-24 07:07:13
126@@ -53,6 +53,7 @@ int omit_dir_times = 0;
127 int update_only = 0;
128 int cvs_exclude = 0;
129 int dry_run = 0;
130+int do_xfers = 1;
131 int ignore_times = 0;
132 int delete_mode = 0;
133 int delete_during = 0;
134@@ -344,6 +345,7 @@ void usage(enum logcode F)
135 rprintf(F," --list-only list the files instead of copying them\n");
136 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
137 rprintf(F," --write-batch=FILE write a batched update to FILE\n");
138+ rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n");
139 rprintf(F," --read-batch=FILE read a batched update from FILE\n");
e621c041 140 rprintf(F," --protocol=NUM force an older protocol version to be used\n");
541bc14e 141 #ifdef INET6
e621c041 142@@ -360,7 +362,8 @@ void usage(enum logcode F)
541bc14e
WD
143 enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
144 OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST,
145 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
146- OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE,
147+ OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH,
148+ OPT_TIMEOUT, OPT_MAX_SIZE,
149 OPT_REFUSED_BASE = 9000};
150
151 static struct poptOption long_options[] = {
e621c041 152@@ -450,6 +453,7 @@ static struct poptOption long_options[]
541bc14e
WD
153 {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links, 0, 0, 0 },
154 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
155 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
156+ {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
157 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
158 {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0},
159 {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
e621c041 160@@ -791,6 +795,11 @@ int parse_arguments(int *argc, const cha
541bc14e
WD
161 write_batch = 1;
162 break;
163
164+ case OPT_ONLY_WRITE_BATCH:
165+ /* batch_name is already set */
166+ write_batch = -1;
167+ break;
168+
169 case OPT_READ_BATCH:
170 /* batch_name is already set */
171 read_batch = 1;
e621c041 172@@ -901,7 +910,7 @@ int parse_arguments(int *argc, const cha
541bc14e
WD
173 "--write-batch and --read-batch can not be used together\n");
174 return 0;
175 }
176- if (write_batch || read_batch) {
177+ if (write_batch > 0 || read_batch) {
178 if (am_server) {
179 rprintf(FINFO,
180 "ignoring --%s-batch option sent to server\n",
e621c041 181@@ -1093,6 +1102,9 @@ int parse_arguments(int *argc, const cha
541bc14e
WD
182 && !am_server)
183 verbose = 1;
184
185+ if (dry_run)
186+ do_xfers = 0;
187+
188 if (verbose && !log_format) {
189 log_format = "%n%L";
190 log_before_transfer = !am_server;
e621c041 191@@ -1246,7 +1258,7 @@ void server_options(char **args,int *arg
541bc14e
WD
192 argstr[x++] = 'b';
193 if (update_only)
194 argstr[x++] = 'u';
195- if (dry_run)
196+ if (!do_xfers)
197 argstr[x++] = 'n';
198 if (preserve_links)
199 argstr[x++] = 'l';
e621c041 200@@ -1374,6 +1386,8 @@ void server_options(char **args,int *arg
541bc14e
WD
201 args[ac++] = "--delete-after";
202 if (force_delete)
203 args[ac++] = "--force";
204+ if (write_batch < 0)
205+ args[ac++] = "--only-write-batch=X";
206 }
207
208 if (size_only)
209--- orig/pipe.c 2005-02-07 20:36:43
210+++ pipe.c 2005-03-24 07:07:13
211@@ -25,7 +25,6 @@ extern int am_sender;
212 extern int am_server;
213 extern int blocking_io;
214 extern int orig_umask;
215-extern int write_batch;
216 extern int filesfrom_fd;
217
218 /**
219@@ -128,10 +127,6 @@ pid_t local_child(int argc, char **argv,
220 am_sender = !am_sender;
221 am_server = 1;
222
223- /* The server side never writes the batch, even if it
224- * is local (it makes the logic easier elsewhere). */
225- write_batch = 0;
226-
227 if (!am_sender)
228 filesfrom_fd = -1;
229
230--- orig/receiver.c 2005-03-24 16:41:46
231+++ receiver.c 2005-03-24 07:07:13
232@@ -21,7 +21,7 @@
233 #include "rsync.h"
234
235 extern int verbose;
236-extern int dry_run;
237+extern int do_xfers;
238 extern int am_daemon;
239 extern int am_server;
240 extern int do_progress;
241@@ -30,6 +30,7 @@ extern int log_format_has_i;
242 extern int daemon_log_format_has_i;
243 extern int csum_length;
244 extern int read_batch;
245+extern int write_batch;
246 extern int batch_gen_fd;
247 extern int protocol_version;
248 extern int relative_paths;
249@@ -435,13 +436,18 @@ int recv_files(int f_in, struct file_lis
250 exit_cleanup(RERR_PROTOCOL);
251 }
252
253- if (dry_run) { /* log the transfer */
254+ if (!do_xfers) { /* log the transfer */
255 if (!am_server && log_format)
256 log_item(file, &stats, iflags, NULL);
257 if (read_batch)
258 discard_receive_data(f_in, file->length);
259 continue;
260 }
261+ if (write_batch < 0) {
262+ log_item(file, &stats, iflags, NULL);
263+ discard_receive_data(f_in, file->length);
264+ continue;
265+ }
266
267 if (read_batch) {
268 while (i > next_gen_i) {
e621c041 269--- orig/rsync.yo 2005-03-28 20:56:55
541bc14e
WD
270+++ rsync.yo 2005-03-27 05:13:01
271@@ -379,6 +379,7 @@ to the detailed description below for a
272 --list-only list the files instead of copying them
273 --bwlimit=KBPS limit I/O bandwidth; KBytes per second
274 --write-batch=FILE write a batched update to FILE
275+ --only-write-batch=FILE like --write-batch but w/o updating dest
276 --read-batch=FILE read a batched update from FILE
e621c041 277 --protocol=NUM force an older protocol version to be used
541bc14e 278 --checksum-seed=NUM set block/file checksum seed (advanced)
e621c041 279@@ -1271,6 +1272,16 @@ dit(bf(--write-batch=FILE)) Record a fil
541bc14e
WD
280 another identical destination with bf(--read-batch). See the "BATCH MODE"
281 section for details.
282
283+dit(bf(--only-write-batch=FILE)) Works like bf(--write-batch), except that
284+no updates are made on the destination system when creating the batch.
285+This lets you transport the changes to the destination system via some
286+other means and then apply the changes via bf(--read-batch). Note that
287+you can feel free to write the batch directly to some portable media: if
288+this media fills to capacity before the end of the transfer, you can just
289+apply that partial transfer to the destination and repeat the whole process
290+to get the rest of the changes (as long as you don't mind a partially
291+updated destination system while the multi-update cycle is happening).
292+
293 dit(bf(--read-batch=FILE)) Apply all of the changes stored in FILE, a
294 file previously generated by bf(--write-batch).
295 If em(FILE) is "-" the batch data will be read from standard input.
e621c041 296--- orig/sender.c 2005-03-28 20:56:55
541bc14e
WD
297+++ sender.c 2005-03-24 07:07:13
298@@ -20,7 +20,7 @@
299 #include "rsync.h"
300
301 extern int verbose;
302-extern int dry_run;
303+extern int do_xfers;
304 extern int am_server;
305 extern int am_daemon;
306 extern int log_before_transfer;
307@@ -34,6 +34,8 @@ extern int updating_basis_file;
308 extern int make_backups;
309 extern int do_progress;
310 extern int inplace;
311+extern int batch_fd;
312+extern int write_batch;
313 extern struct stats stats;
314 extern struct file_list *the_file_list;
315 extern char *log_format;
e621c041 316@@ -208,6 +210,7 @@ void send_files(struct file_list *flist,
541bc14e
WD
317 int save_make_backups = make_backups;
318 int itemizing = am_daemon ? daemon_log_format_has_i
319 : !am_server && log_format_has_i;
320+ int f_xfer = write_batch < 0 ? batch_fd : f_out;
321 int i, j;
322
323 if (verbose > 2)
e621c041 324@@ -230,7 +233,7 @@ void send_files(struct file_list *flist,
541bc14e
WD
325 continue;
326 }
327
328- iflags = read_item_attrs(f_in, f_out, i, &fnamecmp_type,
329+ iflags = read_item_attrs(f_in, f_xfer, i, &fnamecmp_type,
330 xname, &xlen);
331 if (iflags == ITEM_IS_NEW) /* no-op packet */
332 continue;
e621c041 333@@ -266,10 +269,10 @@ void send_files(struct file_list *flist,
541bc14e
WD
334 stats.num_transferred_files++;
335 stats.total_transferred_size += file->length;
336
337- if (dry_run) { /* log the transfer */
338+ if (!do_xfers) { /* log the transfer */
339 if (!am_server && log_format)
340 log_item(file, &stats, iflags, NULL);
341- write_ndx_and_attrs(f_out, i, iflags, fnamecmp_type,
342+ write_ndx_and_attrs(f_xfer, i, iflags, fnamecmp_type,
343 xname, xlen);
344 continue;
345 }
e621c041 346@@ -321,9 +324,9 @@ void send_files(struct file_list *flist,
541bc14e
WD
347 safe_fname(fname), (double)st.st_size);
348 }
349
350- write_ndx_and_attrs(f_out, i, iflags, fnamecmp_type,
351+ write_ndx_and_attrs(f_xfer, i, iflags, fnamecmp_type,
352 xname, xlen);
353- write_sum_head(f_out, s);
354+ write_sum_head(f_xfer, s);
355
356 if (verbose > 2) {
357 rprintf(FINFO, "calling match_sums %s\n",
e621c041 358@@ -337,7 +340,7 @@ void send_files(struct file_list *flist,
541bc14e
WD
359
360 set_compression(fname);
361
362- match_sums(f_out, s, mbuf, st.st_size);
363+ match_sums(f_xfer, s, mbuf, st.st_size);
364 if (do_progress)
365 end_progress(st.st_size);
366