Fixed 2-line fuzz.
[rsync/rsync-patches.git] / remove-sent-files.diff
CommitLineData
8a529471
WD
1After applying this patch and running configure, you MUST run this
2command before "make":
3
4 make proto
5
6
2f2a7c3e 7--- orig/io.c 2005-01-19 20:11:10
4945df2c 8+++ io.c 2005-01-10 10:49:17
0b2fb126 9@@ -244,6 +244,14 @@ static void read_msg_fd(void)
c57f4101
WD
10 read_loop(fd, buf, 4);
11 redo_list_add(IVAL(buf,0));
12 break;
13+ case MSG_SUCCESS:
14+ if (len != 4) {
15+ rprintf(FERROR, "invalid message %d:%d\n", tag, len);
16+ exit_cleanup(RERR_STREAMIO);
17+ }
18+ read_loop(fd, buf, len);
19+ io_multiplex_write(MSG_SUCCESS, buf, len);
20+ break;
21 case MSG_INFO:
22 case MSG_ERROR:
23 case MSG_LOG:
0b2fb126 24@@ -677,6 +685,16 @@ static int readfd_unbuffered(int fd, cha
9cd8d7aa
WD
25 read_loop(fd, iobuf_in, remaining);
26 iobuf_in_ndx = 0;
7b675ff5 27 break;
c57f4101
WD
28+ case MSG_SUCCESS:
29+ if (remaining != 4) {
30+ rprintf(FERROR, "invalid multi-message %d:%ld\n",
31+ tag, (long)remaining);
32+ exit_cleanup(RERR_STREAMIO);
33+ }
34+ read_loop(fd, line, remaining);
35+ successful_send(IVAL(line, 0));
36+ remaining = 0;
7b675ff5 37+ break;
c57f4101
WD
38 case MSG_INFO:
39 case MSG_ERROR:
7b675ff5 40 if (remaining >= sizeof line) {
0b2fb126 41--- orig/main.c 2005-01-17 23:11:45
580f70f0 42+++ main.c 2004-08-13 08:24:23
c57f4101
WD
43@@ -42,6 +42,7 @@ extern int list_only;
44 extern int local_server;
45 extern int log_got_error;
46 extern int module_id;
47+extern int need_messages_from_generator;
48 extern int orig_umask;
d5753a22 49 extern int copy_links;
7628f156 50 extern int keep_dirlinks;
7ad1e159 51@@ -648,6 +649,8 @@ void start_server(int f_in, int f_out, i
c57f4101
WD
52
53 if (am_sender) {
7628f156 54 keep_dirlinks = 0; /* Must be disabled on the sender. */
c57f4101 55+ if (need_messages_from_generator)
580f70f0 56+ io_start_multiplex_in();
9be39c35
WD
57
58 recv_exclude_list(f_in);
59 if (cvs_exclude)
0b2fb126 60@@ -730,6 +733,9 @@ int client_run(int f_in, int f_out, pid_
c57f4101
WD
61 exit_cleanup(status);
62 }
7b675ff5 63
dc8e6f70 64+ if (need_messages_from_generator && !read_batch)
580f70f0 65+ io_start_multiplex_out();
7b675ff5 66+
fe6407b5 67 if (argc == 0)
c57f4101 68 list_only = 1;
7b675ff5 69
2f2a7c3e 70--- orig/options.c 2005-01-20 23:05:34
4945df2c 71+++ options.c 2005-01-10 10:46:47
2f2a7c3e 72@@ -89,8 +89,10 @@ int daemon_bwlimit = 0;
c57f4101 73 int bwlimit = 0;
78114162 74 size_t bwlimit_writemax = 0;
c57f4101
WD
75 int delete_after = 0;
76+int delete_sent_files = 0;
77 int only_existing = 0;
78 int opt_ignore_existing = 0;
f6c3b300 79+int need_messages_from_generator = 0;
c57f4101 80 int max_delete = 0;
58a9031f 81 OFF_T max_size = 0;
f6c3b300 82 int ignore_errors = 0;
2f2a7c3e 83@@ -274,6 +276,7 @@ void usage(enum logcode F)
c57f4101
WD
84 rprintf(F," --delete delete files that don't exist on the sending side\n");
85 rprintf(F," --delete-excluded also delete excluded files on the receiving side\n");
86 rprintf(F," --delete-after receiver deletes after transferring, not before\n");
87+ rprintf(F," --delete-sent-files updated/sent files are removed from sending side\n");
88 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
89 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
58a9031f 90 rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
2f2a7c3e 91@@ -342,6 +345,7 @@ static struct poptOption long_options[]
c57f4101 92 {"ignore-existing", 0, POPT_ARG_NONE, &opt_ignore_existing, 0, 0, 0 },
8b88ca4c
WD
93 {"delete-after", 0, POPT_ARG_NONE, 0, OPT_DELETE_AFTER, 0, 0 },
94 {"delete-excluded", 0, POPT_ARG_NONE, 0, OPT_DELETE_EXCLUDED, 0, 0 },
4945df2c 95+ {"delete-sent-files",0, POPT_ARG_NONE, &delete_sent_files, 0, 0, 0 },
c57f4101
WD
96 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
97 {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 },
8b88ca4c 98 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
2f2a7c3e 99@@ -858,6 +862,9 @@ int parse_arguments(int *argc, const cha
4945df2c
WD
100 if (relative_paths < 0)
101 relative_paths = files_from? 1 : 0;
c57f4101 102
4945df2c
WD
103+ if (delete_sent_files)
104+ need_messages_from_generator = 1;
c57f4101 105+
4945df2c
WD
106 *argv = poptGetArgs(pc);
107 *argc = count_args(*argv);
108
2f2a7c3e
WD
109@@ -1241,6 +1248,9 @@ void server_options(char **args,int *arg
110 if (!implied_dirs && !am_sender)
111 args[ac++] = "--no-implied-dirs";
7b675ff5 112
c57f4101
WD
113+ if (delete_sent_files)
114+ args[ac++] = "--delete-sent-files";
7b675ff5 115+
c57f4101
WD
116 *argc = ac;
117 return;
7b675ff5 118
2f2a7c3e 119--- orig/receiver.c 2005-01-21 00:35:26
580f70f0 120+++ receiver.c 2004-08-13 08:38:51
0b2fb126 121@@ -47,6 +47,7 @@ extern char *backup_dir;
f6c3b300
WD
122 extern char *backup_suffix;
123 extern int backup_suffix_len;
124 extern int cleanup_got_literal;
c57f4101 125+extern int delete_sent_files;
f6c3b300
WD
126 extern int module_id;
127 extern int ignore_errors;
128 extern int orig_umask;
2f2a7c3e 129@@ -322,7 +323,7 @@ int recv_files(int f_in, struct file_lis
c57f4101
WD
130 char *fname, fbuf[MAXPATHLEN];
131 char template[MAXPATHLEN];
132 char fnametmp[MAXPATHLEN];
afbebe13
WD
133- char *fnamecmp, *partialptr;
134+ char *fnamecmp, *partialptr, numbuf[4];
c57f4101 135 char fnamecmpbuf[MAXPATHLEN];
7628f156 136 struct file_struct *file;
dc3ae351 137 struct stats initial_stats;
2f2a7c3e 138@@ -568,7 +569,12 @@ int recv_files(int f_in, struct file_lis
c57f4101
WD
139
140 cleanup_disable();
141
142- if (!recv_ok) {
143+ if (recv_ok) {
144+ if (delete_sent_files) {
145+ SIVAL(numbuf, 0, i);
146+ send_msg(MSG_SUCCESS, numbuf, 4);
147+ }
148+ } else {
8075fb75
WD
149 int msgtype = csum_length == SUM_LENGTH || read_batch ?
150 FERROR : FINFO;
151 if (msgtype == FERROR || verbose) {
2f2a7c3e 152@@ -592,9 +598,8 @@ int recv_files(int f_in, struct file_lis
982426b8 153 keptstr, redostr);
8075fb75
WD
154 }
155 if (csum_length != SUM_LENGTH) {
c57f4101 156- char buf[4];
c57f4101
WD
157- SIVAL(buf, 0, i);
158- send_msg(MSG_REDO, buf, 4);
159+ SIVAL(numbuf, 0, i);
160+ send_msg(MSG_REDO, numbuf, 4);
161 }
162 }
163 }
2f2a7c3e 164--- orig/rsync.h 2005-01-21 00:35:26
13bed3dd 165+++ rsync.h 2004-07-03 20:17:10
54691942 166@@ -60,6 +60,7 @@
2f2a7c3e 167 #define FLAG_DEL_START (1<<0)
c57f4101
WD
168 #define FLAG_HLINK_EOL (1<<1) /* generator only */
169 #define FLAG_MOUNT_POINT (1<<2) /* sender only */
170+#define FLAG_SENT (1<<7) /* sender only */
171
172 /* update this if you make incompatible changes */
0b2fb126 173 #define PROTOCOL_VERSION 29
2f2a7c3e 174@@ -142,6 +143,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
ea238f1c
WD
175 /* Messages types that are sent over the message channel. The logcode
176 * values must all be present here with identical numbers. */
177 enum msgcode {
c57f4101 178+ MSG_SUCCESS=6, /* successfully updated indicated flist index */
ea238f1c
WD
179 MSG_DONE=5, /* current phase is done */
180 MSG_REDO=4, /* reprocess indicated flist index */
181 MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
2f2a7c3e 182--- orig/rsync.yo 2005-01-20 19:47:08
13bed3dd 183+++ rsync.yo 2004-07-03 20:17:10
580f70f0 184@@ -343,6 +343,7 @@ verb(
c57f4101
WD
185 --delete delete files that don't exist on sender
186 --delete-excluded also delete excluded files on receiver
187 --delete-after receiver deletes after transfer, not before
188+ --delete-sent-files updated/sent files are removed from sender
189 --ignore-errors delete even if there are I/O errors
190 --max-delete=NUM don't delete more than NUM files
58a9031f 191 --max-size=SIZE don't transfer any file larger than SIZE
0b2fb126 192@@ -695,6 +696,11 @@ One reason to use --delete-after is to a
7ad1e159
WD
193 the transfer (while the receiving side is scanned for deletions) as this
194 delay might cause the transfer to timeout.
7b675ff5 195
c57f4101
WD
196+dit(bf(--delete-sent-files)) This tells rsync to remove the source files
197+on the sending side that are successfully transferred to the receiving
198+side. Directories are not removed, nor are files that are identical on
199+both systems.
7b675ff5 200+
c57f4101
WD
201 dit(bf(--ignore-errors)) Tells --delete to go ahead and delete files
202 even when there are I/O errors.
7b675ff5 203
0b2fb126 204--- orig/sender.c 2005-01-17 23:11:46
982426b8 205+++ sender.c 2004-07-26 16:49:19
f6c3b300
WD
206@@ -26,6 +26,7 @@ extern int io_error;
207 extern int dry_run;
c57f4101
WD
208 extern int am_server;
209 extern int am_daemon;
c57f4101 210+extern int delete_sent_files;
f6c3b300 211 extern int protocol_version;
0b2fb126 212 extern int updating_basis_file;
a6587818 213 extern int make_backups;
0b2fb126 214@@ -94,7 +95,29 @@ static struct sum_struct *receive_sums(i
c57f4101
WD
215 return s;
216 }
217
218+static struct file_list *the_flist;
219
220+void successful_send(int i)
221+{
222+ char fname[MAXPATHLEN];
223+ struct file_struct *file;
224+ unsigned int offset;
225+
4945df2c 226+ if (!the_flist || i < 0 || i >= the_flist->count)
c57f4101
WD
227+ return;
228+
229+ file = the_flist->files[i];
230+ if (!(file->flags & FLAG_SENT))
231+ return; /* We didn't send it -- impossible! */
232+ if (file->basedir) {
233+ offset = stringjoin(fname, sizeof fname,
234+ file->basedir, "/", NULL);
235+ } else
236+ offset = 0;
237+ f_name_to(file, fname + offset);
238+ if (delete_sent_files && do_unlink(fname) == 0 && verbose > 0)
239+ rprintf(FINFO, "sender removed %s\n", fname + offset);
240+}
241
242 void send_files(struct file_list *flist, int f_out, int f_in)
243 {
0b2fb126 244@@ -113,6 +136,8 @@ void send_files(struct file_list *flist,
c57f4101
WD
245 if (verbose > 2)
246 rprintf(FINFO, "send_files starting\n");
247
248+ the_flist = flist;
249+
250 while (1) {
251 unsigned int offset;
252
0b2fb126 253@@ -248,6 +273,9 @@ void send_files(struct file_list *flist,
982426b8
WD
254 rprintf(FINFO, "sender finished %s\n",
255 safe_fname(fname));
256 }
c57f4101
WD
257+
258+ /* Flag that we actually sent this entry. */
259+ file->flags |= FLAG_SENT;
260 }
a6587818 261 make_backups = save_make_backups;
c57f4101 262