Fixed patch fuzz.
[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-14 02:45:10
42 +++ main.c      2005-02-05 01:24:16
43 @@ -32,12 +32,14 @@ extern int am_daemon;
44  extern int verbose;
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 @@ -441,6 +443,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 @@ -672,6 +680,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 @@ -749,6 +759,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-14 02:45:10
91 +++ options.c   2005-01-23 07:30:51
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 @@ -290,6 +292,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 @@ -366,6 +369,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 @@ -958,6 +962,9 @@ int parse_arguments(int *argc, const cha
125                 return 0;
126         }
127  
128 +       if (delete_sent_files)
129 +               need_messages_from_generator = 1;
130 +
131         *argv = poptGetArgs(pc);
132         *argc = count_args(*argv);
133  
134 @@ -1388,6 +1395,9 @@ void server_options(char **args,int *arg
135         if (fuzzy_basis && am_sender)
136                 args[ac++] = "--fuzzy";
137  
138 +       if (delete_sent_files)
139 +               args[ac++] = "--delete-sent-files";
140 +
141         *argc = ac;
142         return;
143  
144 --- orig/receiver.c     2005-02-14 02:45:10
145 +++ receiver.c  2004-08-13 08:38:51
146 @@ -41,6 +41,7 @@ extern int basis_dir_cnt;
147  extern int make_backups;
148  extern int do_progress;
149  extern int cleanup_got_literal;
150 +extern int delete_sent_files;
151  extern int module_id;
152  extern int ignore_errors;
153  extern int orig_umask;
154 @@ -306,7 +307,7 @@ int recv_files(int f_in, struct file_lis
155         char *fname, fbuf[MAXPATHLEN];
156         char template[MAXPATHLEN];
157         char fnametmp[MAXPATHLEN];
158 -       char *fnamecmp, *partialptr;
159 +       char *fnamecmp, *partialptr, numbuf[4];
160         char fnamecmpbuf[MAXPATHLEN];
161         uchar *delayed_bits = NULL;
162         struct file_struct *file;
163 @@ -567,7 +568,12 @@ int recv_files(int f_in, struct file_lis
164  
165                 cleanup_disable();
166  
167 -               if (!recv_ok) {
168 +               if (recv_ok) {
169 +                       if (delete_sent_files) {
170 +                               SIVAL(numbuf, 0, i);
171 +                               send_msg(MSG_SUCCESS, numbuf, 4);
172 +                       }
173 +               } else {
174                         int msgtype = csum_length == SUM_LENGTH || read_batch ?
175                                 FERROR : FINFO;
176                         if (msgtype == FERROR || verbose) {
177 @@ -591,9 +597,8 @@ int recv_files(int f_in, struct file_lis
178                                         keptstr, redostr);
179                         }
180                         if (csum_length != SUM_LENGTH) {
181 -                               char buf[4];
182 -                               SIVAL(buf, 0, i);
183 -                               send_msg(MSG_REDO, buf, 4);
184 +                               SIVAL(numbuf, 0, i);
185 +                               send_msg(MSG_REDO, numbuf, 4);
186                         }
187                 }
188         }
189 --- orig/rsync.h        2005-02-14 02:45:10
190 +++ rsync.h     2005-02-03 02:04:59
191 @@ -62,6 +62,7 @@
192  #define FLAG_MOUNT_POINT (1<<2)        /* sender only */
193  #define FLAG_NO_FUZZY (1<<2)   /* generator only */
194  #define FLAG_DEL_HERE (1<<3)   /* receiver/generator */
195 +#define FLAG_SENT (1<<7)       /* sender only */
196  
197  /* update this if you make incompatible changes */
198  #define PROTOCOL_VERSION 29
199 @@ -144,6 +145,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
200  /* Messages types that are sent over the message channel.  The logcode
201   * values must all be present here with identical numbers. */
202  enum msgcode {
203 +       MSG_SUCCESS=6,  /* successfully updated indicated flist index */
204         MSG_DONE=5,     /* current phase is done */
205         MSG_REDO=4,     /* reprocess indicated flist index */
206         MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
207 --- orig/rsync.yo       2005-02-14 02:45:11
208 +++ rsync.yo    2005-02-03 02:05:29
209 @@ -338,6 +338,7 @@ to the detailed description below for a 
210       --delete-during         receiver deletes during xfer, not before
211       --delete-after          receiver deletes after transfer, not before
212       --delete-excluded       also delete excluded files on receiver
213 +     --delete-sent-files     updated/sent files are removed from sender
214       --ignore-errors         delete even if there are I/O errors
215       --force                 force deletion of dirs even if not empty
216       --max-delete=NUM        don't delete more than NUM files
217 @@ -734,6 +735,11 @@ this way on the receiver, and for a way 
218  bf(--delete-excluded).
219  See bf(--delete) (which is implied) for more details on file-deletion.
220  
221 +dit(bf(--delete-sent-files)) This tells rsync to remove the source files
222 +on the sending side that are successfully transferred to the receiving
223 +side.  Directories are not removed, nor are files that are identical on
224 +both systems.
225 +
226  dit(bf(--ignore-errors)) Tells bf(--delete) to go ahead and delete files
227  even when there are I/O errors.
228  
229 --- orig/sender.c       2005-02-11 22:24:19
230 +++ sender.c    2004-07-26 16:49:19
231 @@ -26,6 +26,7 @@ extern int io_error;
232  extern int dry_run;
233  extern int am_server;
234  extern int am_daemon;
235 +extern int delete_sent_files;
236  extern int protocol_version;
237  extern int updating_basis_file;
238  extern int make_backups;
239 @@ -94,7 +95,29 @@ static struct sum_struct *receive_sums(i
240         return s;
241  }
242  
243 +static struct file_list *the_flist;
244  
245 +void successful_send(int i)
246 +{
247 +       char fname[MAXPATHLEN];
248 +       struct file_struct *file;
249 +       unsigned int offset;
250 +
251 +       if (!the_flist || i < 0 || i >= the_flist->count)
252 +               return;
253 +
254 +       file = the_flist->files[i];
255 +       if (!(file->flags & FLAG_SENT))
256 +               return; /* We didn't send it -- impossible! */
257 +       if (file->basedir) {
258 +               offset = stringjoin(fname, sizeof fname,
259 +                                   file->basedir, "/", NULL);
260 +       } else
261 +               offset = 0;
262 +       f_name_to(file, fname + offset);
263 +       if (delete_sent_files && do_unlink(fname) == 0 && verbose > 0)
264 +               rprintf(FINFO, "sender removed %s\n", fname + offset);
265 +}
266  
267  void send_files(struct file_list *flist, int f_out, int f_in)
268  {
269 @@ -113,6 +136,8 @@ void send_files(struct file_list *flist,
270         if (verbose > 2)
271                 rprintf(FINFO, "send_files starting\n");
272  
273 +       the_flist = flist;
274 +
275         while (1) {
276                 unsigned int offset;
277  
278 @@ -254,6 +279,9 @@ void send_files(struct file_list *flist,
279                         rprintf(FINFO, "sender finished %s\n",
280                                 safe_fname(fname));
281                 }
282 +
283 +               /* Flag that we actually sent this entry. */
284 +               file->flags |= FLAG_SENT;
285         }
286         make_backups = save_make_backups;
287