Updated to apply cleanly.
[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
8cec1ead
WD
7--- io.c 23 Jun 2004 01:13:09 -0000 1.131
8+++ io.c 30 Jun 2004 00:07:33 -0000
125d7fca 9@@ -225,6 +225,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:
8cec1ead 24@@ -634,6 +642,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) {
8cec1ead
WD
41--- main.c 28 Jun 2004 17:45:40 -0000 1.201
42+++ main.c 30 Jun 2004 00:07:33 -0000
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;
8cec1ead 51@@ -585,6 +586,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);
57 if (!read_batch) {
58 recv_exclude_list(f_in);
59 if (cvs_exclude)
8cec1ead 60@@ -652,6 +655,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
8cec1ead
WD
70--- options.c 20 Jun 2004 19:47:05 -0000 1.157
71+++ options.c 30 Jun 2004 00:07:33 -0000
125d7fca 72@@ -87,6 +87,7 @@ 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;
79 int max_delete = 0;
125d7fca 80@@ -94,6 +95,7 @@ int ignore_errors = 0;
c57f4101
WD
81 int modify_window = 0;
82 int blocking_io = -1;
83 int checksum_seed = 0;
84+int need_messages_from_generator = 0;
85 unsigned int block_size = 0;
86
87
125d7fca 88@@ -258,6 +260,7 @@ void usage(enum logcode F)
c57f4101
WD
89 rprintf(F," --delete delete files that don't exist on the sending side\n");
90 rprintf(F," --delete-excluded also delete excluded files on the receiving side\n");
91 rprintf(F," --delete-after receiver deletes after transferring, not before\n");
92+ rprintf(F," --delete-sent-files updated/sent files are removed from sending side\n");
93 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
94 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
95 rprintf(F," --partial keep partially transferred files\n");
125d7fca 96@@ -308,8 +311,8 @@ void usage(enum logcode F)
c57f4101
WD
97 }
98
99 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
100- OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
101- OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
102+ OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_DELETE_SENT_FILES,
103+ OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_LINK_DEST, OPT_MODIFY_WINDOW,
125d7fca 104 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
c57f4101
WD
105 OPT_REFUSED_BASE = 9000};
106
125d7fca 107@@ -328,6 +331,7 @@ static struct poptOption long_options[]
c57f4101
WD
108 {"ignore-existing", 0, POPT_ARG_NONE, &opt_ignore_existing, 0, 0, 0 },
109 {"delete-after", 0, POPT_ARG_NONE, 0, OPT_DELETE_AFTER, 0, 0 },
110 {"delete-excluded", 0, POPT_ARG_NONE, 0, OPT_DELETE_EXCLUDED, 0, 0 },
111+ {"delete-sent-files",0, POPT_ARG_NONE, 0, OPT_DELETE_SENT_FILES, 0, 0 },
112 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
113 {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 },
114 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
7628f156 115@@ -513,6 +517,11 @@ int parse_arguments(int *argc, const cha
c57f4101
WD
116 delete_mode = 1;
117 break;
118
119+ case OPT_DELETE_SENT_FILES:
120+ delete_sent_files = 1;
121+ need_messages_from_generator = 1;
122+ break;
123+
124 case OPT_EXCLUDE:
78114162
WD
125 if (am_server || sanitize_paths)
126 return 0; /* Impossible... */
7628f156 127@@ -989,6 +998,9 @@ void server_options(char **args,int *arg
c57f4101
WD
128 }
129 }
7b675ff5 130
c57f4101
WD
131+ if (delete_sent_files)
132+ args[ac++] = "--delete-sent-files";
7b675ff5 133+
c57f4101
WD
134 *argc = ac;
135 return;
7b675ff5 136
8cec1ead
WD
137--- receiver.c 29 Jun 2004 15:12:01 -0000 1.83
138+++ receiver.c 30 Jun 2004 00:07:33 -0000
7628f156 139@@ -48,6 +48,7 @@ extern int ignore_errors;
54691942 140 extern int orig_umask;
8a529471 141 extern int keep_partial;
7b675ff5 142 extern int checksum_seed;
c57f4101
WD
143+extern int delete_sent_files;
144
145 static void delete_one(char *fn, int is_dir)
146 {
7628f156 147@@ -300,7 +301,7 @@ int recv_files(int f_in,struct file_list
c57f4101
WD
148 char *fname, fbuf[MAXPATHLEN];
149 char template[MAXPATHLEN];
150 char fnametmp[MAXPATHLEN];
151- char *fnamecmp;
152+ char *fnamecmp, numbuf[4];
153 char fnamecmpbuf[MAXPATHLEN];
154 struct map_struct *mapbuf;
7628f156 155 struct file_struct *file;
8cec1ead 156@@ -484,16 +485,20 @@ int recv_files(int f_in,struct file_list
c57f4101
WD
157
158 cleanup_disable();
159
160- if (!recv_ok) {
161+ if (recv_ok) {
162+ if (delete_sent_files) {
163+ SIVAL(numbuf, 0, i);
164+ send_msg(MSG_SUCCESS, numbuf, 4);
165+ }
166+ } else {
167 if (csum_length == SUM_LENGTH) {
168 rprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n",
169 full_fname(fname));
170 } else {
171- char buf[4];
172 if (verbose > 1)
173 rprintf(FINFO,"redoing %s(%d)\n",fname,i);
174- SIVAL(buf, 0, i);
175- send_msg(MSG_REDO, buf, 4);
176+ SIVAL(numbuf, 0, i);
177+ send_msg(MSG_REDO, numbuf, 4);
178 }
179 }
180 }
7b675ff5 181--- rsync.h 16 May 2004 07:28:24 -0000 1.204
8cec1ead 182+++ rsync.h 30 Jun 2004 00:07:34 -0000
54691942 183@@ -60,6 +60,7 @@
c57f4101
WD
184 #define FLAG_TOP_DIR (1<<0)
185 #define FLAG_HLINK_EOL (1<<1) /* generator only */
186 #define FLAG_MOUNT_POINT (1<<2) /* sender only */
187+#define FLAG_SENT (1<<7) /* sender only */
188
189 /* update this if you make incompatible changes */
190 #define PROTOCOL_VERSION 28
8a529471 191@@ -123,6 +124,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
ea238f1c
WD
192 /* Messages types that are sent over the message channel. The logcode
193 * values must all be present here with identical numbers. */
194 enum msgcode {
c57f4101 195+ MSG_SUCCESS=6, /* successfully updated indicated flist index */
ea238f1c
WD
196 MSG_DONE=5, /* current phase is done */
197 MSG_REDO=4, /* reprocess indicated flist index */
198 MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
125d7fca 199--- rsync.yo 5 Jun 2004 16:16:30 -0000 1.171
8cec1ead 200+++ rsync.yo 30 Jun 2004 00:07:34 -0000
125d7fca 201@@ -313,6 +313,7 @@ verb(
c57f4101
WD
202 --delete delete files that don't exist on sender
203 --delete-excluded also delete excluded files on receiver
204 --delete-after receiver deletes after transfer, not before
205+ --delete-sent-files updated/sent files are removed from sender
206 --ignore-errors delete even if there are I/O errors
207 --max-delete=NUM don't delete more than NUM files
208 --partial keep partially transferred files
125d7fca 209@@ -603,6 +604,11 @@ receiving side before transferring files
c57f4101
WD
210 sufficient space on the receiving filesystem. If you want to delete
211 after transferring, use the --delete-after switch. Implies --delete.
7b675ff5 212
c57f4101
WD
213+dit(bf(--delete-sent-files)) This tells rsync to remove the source files
214+on the sending side that are successfully transferred to the receiving
215+side. Directories are not removed, nor are files that are identical on
216+both systems.
7b675ff5 217+
c57f4101
WD
218 dit(bf(--ignore-errors)) Tells --delete to go ahead and delete files
219 even when there are I/O errors.
7b675ff5 220
7628f156 221--- sender.c 18 Jun 2004 16:55:12 -0000 1.41
8cec1ead 222+++ sender.c 30 Jun 2004 00:07:34 -0000
c57f4101
WD
223@@ -27,6 +27,7 @@ extern int dry_run;
224 extern int am_server;
225 extern int am_daemon;
226 extern int protocol_version;
227+extern int delete_sent_files;
228
229
230 /**
231@@ -104,7 +105,29 @@ static struct sum_struct *receive_sums(i
232 return s;
233 }
234
235+static struct file_list *the_flist;
236
237+void successful_send(int i)
238+{
239+ char fname[MAXPATHLEN];
240+ struct file_struct *file;
241+ unsigned int offset;
242+
243+ if (!the_flist)
244+ return;
245+
246+ file = the_flist->files[i];
247+ if (!(file->flags & FLAG_SENT))
248+ return; /* We didn't send it -- impossible! */
249+ if (file->basedir) {
250+ offset = stringjoin(fname, sizeof fname,
251+ file->basedir, "/", NULL);
252+ } else
253+ offset = 0;
254+ f_name_to(file, fname + offset);
255+ if (delete_sent_files && do_unlink(fname) == 0 && verbose > 0)
256+ rprintf(FINFO, "sender removed %s\n", fname + offset);
257+}
258
259 void send_files(struct file_list *flist, int f_out, int f_in)
260 {
261@@ -129,6 +152,8 @@ void send_files(struct file_list *flist,
262 if (verbose > 2)
263 rprintf(FINFO, "send_files starting\n");
264
265+ the_flist = flist;
266+
267 while (1) {
268 unsigned int offset;
269
fe6407b5 270@@ -300,6 +325,9 @@ void send_files(struct file_list *flist,
c57f4101
WD
271
272 if (verbose > 2)
273 rprintf(FINFO, "sender finished %s\n", fname);
274+
275+ /* Flag that we actually sent this entry. */
276+ file->flags |= FLAG_SENT;
277 }
278
279 if (verbose > 2)