Fixed compile problem that crept into the code due to a
[rsync-patches.git] / remove-sent-files.diff
1 After applying this patch and running configure, you MUST run this
2 command before "make":
3
4     make proto
5
6
7 --- orig/io.c   2005-02-03 02:04:20
8 +++ io.c        2005-01-10 10:49:17
9 @@ -244,6 +244,14 @@ static void read_msg_fd(void)
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:
24 @@ -677,6 +685,16 @@ static int readfd_unbuffered(int fd, cha
25                         read_loop(fd, iobuf_in, remaining);
26                         iobuf_in_ndx = 0;
27                         break;
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;
37 +                       break;
38                 case MSG_INFO:
39                 case MSG_ERROR:
40                         if (remaining >= sizeof line) {
41 --- orig/main.c 2005-02-15 19:27:04
42 +++ main.c      2005-02-05 01:24:16
43 @@ -33,12 +33,14 @@ extern int verbose;
44  extern int itemize_changes;
45  extern int blocking_io;
46  extern int delete_before;
47 +extern int delete_sent_files;
48  extern int daemon_over_rsh;
49  extern int do_stats;
50  extern int dry_run;
51  extern int list_only;
52  extern int log_got_error;
53  extern int module_id;
54 +extern int need_messages_from_generator;
55  extern int orig_umask;
56  extern int copy_links;
57  extern int keep_dirlinks;
58 @@ -442,6 +444,12 @@ static void do_server_sender(int f_in, i
59                 exit_cleanup(RERR_SYNTAX);
60                 return;
61         }
62 +       if (am_daemon && lp_read_only(module_id) && delete_sent_files) {
63 +               rprintf(FERROR,
64 +                   "ERROR: --delete-sent-files cannot be used with a read-only module\n");
65 +               exit_cleanup(RERR_SYNTAX);
66 +               return;
67 +       }
68  
69         if (!relative_paths && !push_dir(dir)) {
70                 rsyserr(FERROR, errno, "push_dir#3 %s failed",
71 @@ -673,6 +681,8 @@ void start_server(int f_in, int f_out, i
72  
73         if (am_sender) {
74                 keep_dirlinks = 0; /* Must be disabled on the sender. */
75 +               if (need_messages_from_generator)
76 +                       io_start_multiplex_in();
77  
78                 recv_filter_list(f_in);
79                 do_server_sender(f_in, f_out, argc, argv);
80 @@ -750,6 +760,9 @@ int client_run(int f_in, int f_out, pid_
81                 exit_cleanup(status);
82         }
83  
84 +       if (need_messages_from_generator && !read_batch)
85 +               io_start_multiplex_out();
86 +
87         if (argc == 0)
88                 list_only |= 1;
89  
90 --- orig/options.c      2005-02-15 19:27:05
91 +++ options.c   2005-02-14 17:48:01
92 @@ -59,6 +59,7 @@ int delete_during = 0;
93  int delete_before = 0;
94  int delete_after = 0;
95  int delete_excluded = 0;
96 +int delete_sent_files = 0;
97  int one_file_system = 0;
98  int protocol_version = PROTOCOL_VERSION;
99  int sparse_files = 0;
100 @@ -93,6 +94,7 @@ int fuzzy_basis = 0;
101  size_t bwlimit_writemax = 0;
102  int only_existing = 0;
103  int opt_ignore_existing = 0;
104 +int need_messages_from_generator = 0;
105  int max_delete = 0;
106  OFF_T max_size = 0;
107  int ignore_errors = 0;
108 @@ -291,6 +293,7 @@ void usage(enum logcode F)
109    rprintf(F,"     --delete-during         receiver deletes during transfer, not before\n");
110    rprintf(F,"     --delete-after          receiver deletes after transfer, not before\n");
111    rprintf(F,"     --delete-excluded       also delete excluded files on the receiving side\n");
112 +  rprintf(F,"     --delete-sent-files     updated/sent files are removed from sending side\n");
113    rprintf(F,"     --ignore-errors         delete even if there are I/O errors\n");
114    rprintf(F,"     --force                 force deletion of directories even if not empty\n");
115    rprintf(F,"     --max-delete=NUM        don't delete more than NUM files\n");
116 @@ -368,6 +371,7 @@ static struct poptOption long_options[] 
117    {"delete-during",    0,  POPT_ARG_NONE,   &delete_during, 0, 0, 0 },
118    {"delete-after",     0,  POPT_ARG_NONE,   &delete_after, 0, 0, 0 },
119    {"delete-excluded",  0,  POPT_ARG_NONE,   &delete_excluded, 0, 0, 0 },
120 +  {"delete-sent-files",0,  POPT_ARG_NONE,   &delete_sent_files, 0, 0, 0 },
121    {"force",            0,  POPT_ARG_NONE,   &force_delete, 0, 0, 0 },
122    {"numeric-ids",      0,  POPT_ARG_NONE,   &numeric_ids, 0, 0, 0 },
123    {"filter",          'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
124 @@ -961,6 +965,14 @@ int parse_arguments(int *argc, const cha
125                 return 0;
126         }
127  
128 +       if (delete_sent_files) {
129 +               if (refused_delete) {
130 +                       create_refuse_error(refused_delete);
131 +                       return 0;
132 +               }
133 +               need_messages_from_generator = 1;
134 +       }
135 +
136         *argv = poptGetArgs(pc);
137         *argc = count_args(*argv);
138  
139 @@ -1393,6 +1405,9 @@ void server_options(char **args,int *arg
140         if (fuzzy_basis && am_sender)
141                 args[ac++] = "--fuzzy";
142  
143 +       if (delete_sent_files)
144 +               args[ac++] = "--delete-sent-files";
145 +
146         *argc = ac;
147         return;
148  
149 --- orig/receiver.c     2005-02-15 19:27:05
150 +++ receiver.c  2004-08-13 08:38:51
151 @@ -42,6 +42,7 @@ extern int basis_dir_cnt;
152  extern int make_backups;
153  extern int do_progress;
154  extern int cleanup_got_literal;
155 +extern int delete_sent_files;
156  extern int module_id;
157  extern int ignore_errors;
158  extern int orig_umask;
159 @@ -307,7 +308,7 @@ int recv_files(int f_in, struct file_lis
160         char *fname, fbuf[MAXPATHLEN];
161         char template[MAXPATHLEN];
162         char fnametmp[MAXPATHLEN];
163 -       char *fnamecmp, *partialptr;
164 +       char *fnamecmp, *partialptr, numbuf[4];
165         char fnamecmpbuf[MAXPATHLEN];
166         uchar *delayed_bits = NULL;
167         struct file_struct *file;
168 @@ -569,7 +570,12 @@ int recv_files(int f_in, struct file_lis
169  
170                 cleanup_disable();
171  
172 -               if (!recv_ok) {
173 +               if (recv_ok) {
174 +                       if (delete_sent_files) {
175 +                               SIVAL(numbuf, 0, i);
176 +                               send_msg(MSG_SUCCESS, numbuf, 4);
177 +                       }
178 +               } else {
179                         int msgtype = csum_length == SUM_LENGTH || read_batch ?
180                                 FERROR : FINFO;
181                         if (msgtype == FERROR || verbose) {
182 @@ -593,9 +599,8 @@ int recv_files(int f_in, struct file_lis
183                                         keptstr, redostr);
184                         }
185                         if (csum_length != SUM_LENGTH) {
186 -                               char buf[4];
187 -                               SIVAL(buf, 0, i);
188 -                               send_msg(MSG_REDO, buf, 4);
189 +                               SIVAL(numbuf, 0, i);
190 +                               send_msg(MSG_REDO, numbuf, 4);
191                         }
192                 }
193         }
194 --- orig/rsync.h        2005-02-15 19:27:05
195 +++ rsync.h     2005-02-03 02:04:59
196 @@ -62,6 +62,7 @@
197  #define FLAG_MOUNT_POINT (1<<2)        /* sender only */
198  #define FLAG_NO_FUZZY (1<<2)   /* generator only */
199  #define FLAG_DEL_HERE (1<<3)   /* receiver/generator */
200 +#define FLAG_SENT (1<<7)       /* sender only */
201  
202  /* update this if you make incompatible changes */
203  #define PROTOCOL_VERSION 29
204 @@ -144,6 +145,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
205  /* Messages types that are sent over the message channel.  The logcode
206   * values must all be present here with identical numbers. */
207  enum msgcode {
208 +       MSG_SUCCESS=6,  /* successfully updated indicated flist index */
209         MSG_DONE=5,     /* current phase is done */
210         MSG_REDO=4,     /* reprocess indicated flist index */
211         MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
212 --- orig/rsync.yo       2005-02-15 19:27:05
213 +++ rsync.yo    2005-02-03 02:05:29
214 @@ -338,6 +338,7 @@ to the detailed description below for a 
215       --delete-during         receiver deletes during xfer, not before
216       --delete-after          receiver deletes after transfer, not before
217       --delete-excluded       also delete excluded files on receiver
218 +     --delete-sent-files     updated/sent files are removed from sender
219       --ignore-errors         delete even if there are I/O errors
220       --force                 force deletion of dirs even if not empty
221       --max-delete=NUM        don't delete more than NUM files
222 @@ -735,6 +736,11 @@ this way on the receiver, and for a way 
223  bf(--delete-excluded).
224  See bf(--delete) (which is implied) for more details on file-deletion.
225  
226 +dit(bf(--delete-sent-files)) This tells rsync to remove the source files
227 +on the sending side that are successfully transferred to the receiving
228 +side.  Directories, symlinks, and devices are not removed, nor are files
229 +that were not transferred from the sender to the receiver.
230 +
231  dit(bf(--ignore-errors)) Tells bf(--delete) to go ahead and delete files
232  even when there are I/O errors.
233  
234 --- orig/sender.c       2005-02-15 19:27:05
235 +++ sender.c    2004-07-26 16:49:19
236 @@ -27,6 +27,7 @@ extern int io_error;
237  extern int dry_run;
238  extern int am_server;
239  extern int am_daemon;
240 +extern int delete_sent_files;
241  extern int protocol_version;
242  extern int updating_basis_file;
243  extern int make_backups;
244 @@ -95,7 +96,29 @@ static struct sum_struct *receive_sums(i
245         return s;
246  }
247  
248 +static struct file_list *the_flist;
249  
250 +void successful_send(int i)
251 +{
252 +       char fname[MAXPATHLEN];
253 +       struct file_struct *file;
254 +       unsigned int offset;
255 +
256 +       if (!the_flist || i < 0 || i >= the_flist->count)
257 +               return;
258 +
259 +       file = the_flist->files[i];
260 +       if (!(file->flags & FLAG_SENT))
261 +               return; /* We didn't send it -- impossible! */
262 +       if (file->dir.root) {
263 +               offset = stringjoin(fname, sizeof fname,
264 +                                   file->dir.root, "/", NULL);
265 +       } else
266 +               offset = 0;
267 +       f_name_to(file, fname + offset);
268 +       if (delete_sent_files && do_unlink(fname) == 0 && verbose)
269 +               rprintf(FINFO, "sender removed %s\n", fname + offset);
270 +}
271  
272  void send_files(struct file_list *flist, int f_out, int f_in)
273  {
274 @@ -114,6 +137,8 @@ void send_files(struct file_list *flist,
275         if (verbose > 2)
276                 rprintf(FINFO, "send_files starting\n");
277  
278 +       the_flist = flist;
279 +
280         while (1) {
281                 unsigned int offset;
282  
283 @@ -256,6 +281,9 @@ void send_files(struct file_list *flist,
284                         rprintf(FINFO, "sender finished %s\n",
285                                 safe_fname(fname));
286                 }
287 +
288 +               /* Flag that we actually sent this entry. */
289 +               file->flags |= FLAG_SENT;
290         }
291         make_backups = save_make_backups;
292