- Write a length prefix instead of a trailing null for the name that
[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
9be39c35 7--- orig/io.c 2004-07-15 02:21:10
13bed3dd 8+++ io.c 2004-07-03 20:17:10
9be39c35 9@@ -231,6 +231,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:
9be39c35 24@@ -640,6 +648,16 @@ static int readfd_unbuffered(int fd, cha
c57f4101
WD
25 read_loop(fd, buffer, remaining);
26 bufferIdx = 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) {
9be39c35
WD
41--- orig/main.c 2004-07-15 17:02:03
42+++ main.c 2004-07-15 02:29:03
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;
7628f156 49 extern int keep_dirlinks;
c57f4101 50 extern int preserve_hard_links;
9be39c35 51@@ -598,6 +599,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
WD
55+ if (need_messages_from_generator)
56+ io_start_multiplex_in(f_in);
9be39c35
WD
57
58 recv_exclude_list(f_in);
59 if (cvs_exclude)
60@@ -677,6 +680,9 @@ int client_run(int f_in, int f_out, pid_
c57f4101
WD
61 exit_cleanup(status);
62 }
7b675ff5 63
c57f4101
WD
64+ if (need_messages_from_generator)
65+ io_start_multiplex_out(f_out);
7b675ff5 66+
fe6407b5 67 if (argc == 0)
c57f4101 68 list_only = 1;
7b675ff5 69
f6c3b300
WD
70--- orig/options.c 2004-07-16 20:07:22
71+++ options.c 2004-07-16 20:09:54
72@@ -87,8 +87,10 @@ int size_only = 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;
f6c3b300 81 int ignore_errors = 0;
c57f4101 82 int modify_window = 0;
f6c3b300 83@@ -264,6 +266,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");
90 rprintf(F," --partial keep partially transferred files\n");
f6c3b300 91@@ -314,8 +317,8 @@ void usage(enum logcode F)
c57f4101
WD
92 }
93
94 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
95- OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
96- OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
97+ OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_DELETE_SENT_FILES,
98+ OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_LINK_DEST, OPT_MODIFY_WINDOW,
125d7fca 99 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
c57f4101
WD
100 OPT_REFUSED_BASE = 9000};
101
f6c3b300 102@@ -334,6 +337,7 @@ static struct poptOption long_options[]
c57f4101
WD
103 {"ignore-existing", 0, POPT_ARG_NONE, &opt_ignore_existing, 0, 0, 0 },
104 {"delete-after", 0, POPT_ARG_NONE, 0, OPT_DELETE_AFTER, 0, 0 },
105 {"delete-excluded", 0, POPT_ARG_NONE, 0, OPT_DELETE_EXCLUDED, 0, 0 },
106+ {"delete-sent-files",0, POPT_ARG_NONE, 0, OPT_DELETE_SENT_FILES, 0, 0 },
107 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
108 {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 },
109 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
f6c3b300 110@@ -520,6 +524,11 @@ int parse_arguments(int *argc, const cha
c57f4101
WD
111 delete_mode = 1;
112 break;
113
114+ case OPT_DELETE_SENT_FILES:
115+ delete_sent_files = 1;
116+ need_messages_from_generator = 1;
117+ break;
118+
119 case OPT_EXCLUDE:
78114162
WD
120 if (am_server || sanitize_paths)
121 return 0; /* Impossible... */
f6c3b300 122@@ -1019,6 +1028,9 @@ void server_options(char **args,int *arg
c57f4101
WD
123 }
124 }
7b675ff5 125
c57f4101
WD
126+ if (delete_sent_files)
127+ args[ac++] = "--delete-sent-files";
7b675ff5 128+
c57f4101
WD
129 *argc = ac;
130 return;
7b675ff5 131
f6c3b300
WD
132--- orig/receiver.c 2004-07-16 20:07:22
133+++ receiver.c 2004-07-16 20:09:48
134@@ -43,6 +43,7 @@ extern char *backup_dir;
135 extern char *backup_suffix;
136 extern int backup_suffix_len;
137 extern int cleanup_got_literal;
c57f4101 138+extern int delete_sent_files;
f6c3b300
WD
139 extern int module_id;
140 extern int ignore_errors;
141 extern int orig_umask;
142@@ -311,7 +312,7 @@ int recv_files(int f_in, struct file_lis
c57f4101
WD
143 char *fname, fbuf[MAXPATHLEN];
144 char template[MAXPATHLEN];
145 char fnametmp[MAXPATHLEN];
146- char *fnamecmp;
147+ char *fnamecmp, numbuf[4];
148 char fnamecmpbuf[MAXPATHLEN];
149 struct map_struct *mapbuf;
7628f156 150 struct file_struct *file;
f6c3b300 151@@ -508,16 +509,20 @@ int recv_files(int f_in, struct file_lis
c57f4101
WD
152
153 cleanup_disable();
154
155- if (!recv_ok) {
156+ if (recv_ok) {
157+ if (delete_sent_files) {
158+ SIVAL(numbuf, 0, i);
159+ send_msg(MSG_SUCCESS, numbuf, 4);
160+ }
161+ } else {
162 if (csum_length == SUM_LENGTH) {
163 rprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n",
164 full_fname(fname));
165 } else {
166- char buf[4];
167 if (verbose > 1)
168 rprintf(FINFO,"redoing %s(%d)\n",fname,i);
169- SIVAL(buf, 0, i);
170- send_msg(MSG_REDO, buf, 4);
171+ SIVAL(numbuf, 0, i);
172+ send_msg(MSG_REDO, numbuf, 4);
173 }
174 }
175 }
f6c3b300 176--- orig/rsync.h 2004-07-16 20:07:23
13bed3dd 177+++ rsync.h 2004-07-03 20:17:10
54691942 178@@ -60,6 +60,7 @@
c57f4101
WD
179 #define FLAG_TOP_DIR (1<<0)
180 #define FLAG_HLINK_EOL (1<<1) /* generator only */
181 #define FLAG_MOUNT_POINT (1<<2) /* sender only */
182+#define FLAG_SENT (1<<7) /* sender only */
183
184 /* update this if you make incompatible changes */
185 #define PROTOCOL_VERSION 28
8a529471 186@@ -123,6 +124,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
ea238f1c
WD
187 /* Messages types that are sent over the message channel. The logcode
188 * values must all be present here with identical numbers. */
189 enum msgcode {
c57f4101 190+ MSG_SUCCESS=6, /* successfully updated indicated flist index */
ea238f1c
WD
191 MSG_DONE=5, /* current phase is done */
192 MSG_REDO=4, /* reprocess indicated flist index */
193 MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
f6c3b300 194--- orig/rsync.yo 2004-07-16 20:07:23
13bed3dd 195+++ rsync.yo 2004-07-03 20:17:10
f6c3b300 196@@ -314,6 +314,7 @@ verb(
c57f4101
WD
197 --delete delete files that don't exist on sender
198 --delete-excluded also delete excluded files on receiver
199 --delete-after receiver deletes after transfer, not before
200+ --delete-sent-files updated/sent files are removed from sender
201 --ignore-errors delete even if there are I/O errors
202 --max-delete=NUM don't delete more than NUM files
203 --partial keep partially transferred files
f6c3b300 204@@ -615,6 +616,11 @@ receiving side before transferring files
c57f4101
WD
205 sufficient space on the receiving filesystem. If you want to delete
206 after transferring, use the --delete-after switch. Implies --delete.
7b675ff5 207
c57f4101
WD
208+dit(bf(--delete-sent-files)) This tells rsync to remove the source files
209+on the sending side that are successfully transferred to the receiving
210+side. Directories are not removed, nor are files that are identical on
211+both systems.
7b675ff5 212+
c57f4101
WD
213 dit(bf(--ignore-errors)) Tells --delete to go ahead and delete files
214 even when there are I/O errors.
7b675ff5 215
f6c3b300
WD
216--- orig/sender.c 2004-07-16 20:07:23
217+++ sender.c 2004-07-16 20:10:19
218@@ -26,6 +26,7 @@ extern int io_error;
219 extern int dry_run;
c57f4101
WD
220 extern int am_server;
221 extern int am_daemon;
c57f4101 222+extern int delete_sent_files;
f6c3b300
WD
223 extern int protocol_version;
224 extern struct stats stats;
c57f4101 225
f6c3b300 226@@ -107,7 +108,29 @@ static struct sum_struct *receive_sums(i
c57f4101
WD
227 return s;
228 }
229
230+static struct file_list *the_flist;
231
232+void successful_send(int i)
233+{
234+ char fname[MAXPATHLEN];
235+ struct file_struct *file;
236+ unsigned int offset;
237+
238+ if (!the_flist)
239+ return;
240+
241+ file = the_flist->files[i];
242+ if (!(file->flags & FLAG_SENT))
243+ return; /* We didn't send it -- impossible! */
244+ if (file->basedir) {
245+ offset = stringjoin(fname, sizeof fname,
246+ file->basedir, "/", NULL);
247+ } else
248+ offset = 0;
249+ f_name_to(file, fname + offset);
250+ if (delete_sent_files && do_unlink(fname) == 0 && verbose > 0)
251+ rprintf(FINFO, "sender removed %s\n", fname + offset);
252+}
253
254 void send_files(struct file_list *flist, int f_out, int f_in)
255 {
f6c3b300 256@@ -125,6 +148,8 @@ void send_files(struct file_list *flist,
c57f4101
WD
257 if (verbose > 2)
258 rprintf(FINFO, "send_files starting\n");
259
260+ the_flist = flist;
261+
262 while (1) {
263 unsigned int offset;
264
f6c3b300 265@@ -247,6 +272,9 @@ void send_files(struct file_list *flist,
c57f4101
WD
266
267 if (verbose > 2)
268 rprintf(FINFO, "sender finished %s\n", fname);
269+
270+ /* Flag that we actually sent this entry. */
271+ file->flags |= FLAG_SENT;
272 }
273
274 if (verbose > 2)