Fixed failing hunks.
[rsync/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-01-19 20:11:10
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-01-23 07:27:24
42 +++ main.c      2004-08-13 08:24:23
43 @@ -43,6 +43,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;
49  extern int copy_links;
50  extern int keep_dirlinks;
51 @@ -649,6 +650,8 @@ void start_server(int f_in, int f_out, i
52  
53         if (am_sender) {
54                 keep_dirlinks = 0; /* Must be disabled on the sender. */
55 +               if (need_messages_from_generator)
56 +                       io_start_multiplex_in();
57  
58                 recv_exclude_list(f_in);
59                 if (cvs_exclude)
60 @@ -731,6 +734,9 @@ int client_run(int f_in, int f_out, pid_
61                 exit_cleanup(status);
62         }
63  
64 +       if (need_messages_from_generator && !read_batch)
65 +               io_start_multiplex_out();
66 +
67         if (argc == 0)
68                 list_only |= 1;
69  
70 --- orig/options.c      2005-01-23 01:45:43
71 +++ options.c   2005-01-23 07:30:51
72 @@ -57,6 +57,7 @@ int delete_mode = 0;
73  int delete_before = 0;
74  int delete_after = 0;
75  int delete_excluded = 0;
76 +int delete_sent_files = 0;
77  int one_file_system = 0;
78  int protocol_version = PROTOCOL_VERSION;
79  int sparse_files = 0;
80 @@ -92,6 +93,7 @@ int bwlimit = 0;
81  size_t bwlimit_writemax = 0;
82  int only_existing = 0;
83  int opt_ignore_existing = 0;
84 +int need_messages_from_generator = 0;
85  int max_delete = 0;
86  OFF_T max_size = 0;
87  int ignore_errors = 0;
88 @@ -276,6 +278,7 @@ void usage(enum logcode F)
89    rprintf(F,"     --delete                delete files that don't exist on the sending side\n");
90    rprintf(F,"     --delete-after          receiver deletes after transferring, not before\n");
91    rprintf(F,"     --delete-excluded       also delete excluded files on the receiving side\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,"     --force                 force deletion of directories even if not empty\n");
95    rprintf(F,"     --max-delete=NUM        don't delete more than NUM files\n");
96 @@ -343,6 +346,7 @@ static struct poptOption long_options[] 
97    {"delete",           0,  POPT_ARG_NONE,   &delete_before, 0, 0, 0 },
98    {"delete-after",     0,  POPT_ARG_NONE,   &delete_after, 0, 0, 0 },
99    {"delete-excluded",  0,  POPT_ARG_NONE,   &delete_excluded, 0, 0, 0 },
100 +  {"delete-sent-files",0,  POPT_ARG_NONE,   &delete_sent_files, 0, 0, 0 },
101    {"force",            0,  POPT_ARG_NONE,   &force_delete, 0, 0, 0 },
102    {"numeric-ids",      0,  POPT_ARG_NONE,   &numeric_ids, 0, 0, 0 },
103    {"exclude",          0,  POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
104 @@ -858,6 +862,9 @@ int parse_arguments(int *argc, const cha
105         if (delete_excluded && !delete_mode)
106                 delete_mode = delete_before = 1;
107  
108 +       if (delete_sent_files)
109 +               need_messages_from_generator = 1;
110 +
111         *argv = poptGetArgs(pc);
112         *argc = count_args(*argv);
113  
114 @@ -1244,6 +1251,9 @@ void server_options(char **args,int *arg
115         if (!implied_dirs && !am_sender)
116                 args[ac++] = "--no-implied-dirs";
117  
118 +       if (delete_sent_files)
119 +               args[ac++] = "--delete-sent-files";
120 +
121         *argc = ac;
122         return;
123  
124 --- orig/receiver.c     2005-01-23 07:27:24
125 +++ receiver.c  2004-08-13 08:38:51
126 @@ -47,6 +47,7 @@ extern char *backup_dir;
127  extern char *backup_suffix;
128  extern int backup_suffix_len;
129  extern int cleanup_got_literal;
130 +extern int delete_sent_files;
131  extern int module_id;
132  extern int ignore_errors;
133  extern int orig_umask;
134 @@ -322,7 +323,7 @@ int recv_files(int f_in, struct file_lis
135         char *fname, fbuf[MAXPATHLEN];
136         char template[MAXPATHLEN];
137         char fnametmp[MAXPATHLEN];
138 -       char *fnamecmp, *partialptr;
139 +       char *fnamecmp, *partialptr, numbuf[4];
140         char fnamecmpbuf[MAXPATHLEN];
141         struct file_struct *file;
142         struct stats initial_stats;
143 @@ -568,7 +569,12 @@ int recv_files(int f_in, struct file_lis
144  
145                 cleanup_disable();
146  
147 -               if (!recv_ok) {
148 +               if (recv_ok) {
149 +                       if (delete_sent_files) {
150 +                               SIVAL(numbuf, 0, i);
151 +                               send_msg(MSG_SUCCESS, numbuf, 4);
152 +                       }
153 +               } else {
154                         int msgtype = csum_length == SUM_LENGTH || read_batch ?
155                                 FERROR : FINFO;
156                         if (msgtype == FERROR || verbose) {
157 @@ -592,9 +598,8 @@ int recv_files(int f_in, struct file_lis
158                                         keptstr, redostr);
159                         }
160                         if (csum_length != SUM_LENGTH) {
161 -                               char buf[4];
162 -                               SIVAL(buf, 0, i);
163 -                               send_msg(MSG_REDO, buf, 4);
164 +                               SIVAL(numbuf, 0, i);
165 +                               send_msg(MSG_REDO, numbuf, 4);
166                         }
167                 }
168         }
169 --- orig/rsync.h        2005-01-21 00:35:26
170 +++ rsync.h     2004-07-03 20:17:10
171 @@ -60,6 +60,7 @@
172  #define FLAG_DEL_START (1<<0)
173  #define FLAG_HLINK_EOL (1<<1)  /* generator only */
174  #define FLAG_MOUNT_POINT (1<<2)        /* sender only */
175 +#define FLAG_SENT (1<<7)       /* sender only */
176  
177  /* update this if you make incompatible changes */
178  #define PROTOCOL_VERSION 29
179 @@ -142,6 +143,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
180  /* Messages types that are sent over the message channel.  The logcode
181   * values must all be present here with identical numbers. */
182  enum msgcode {
183 +       MSG_SUCCESS=6,  /* successfully updated indicated flist index */
184         MSG_DONE=5,     /* current phase is done */
185         MSG_REDO=4,     /* reprocess indicated flist index */
186         MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
187 --- orig/rsync.yo       2005-01-22 22:48:52
188 +++ rsync.yo    2005-01-23 07:31:03
189 @@ -343,6 +343,7 @@ verb(
190       --delete                delete files that don't exist on sender
191       --delete-after          receiver deletes after transfer, not before
192       --delete-excluded       also delete excluded files on receiver
193 +     --delete-sent-files     updated/sent files are removed from sender
194       --ignore-errors         delete even if there are I/O errors
195       --force                 force deletion of dirs even if not empty
196       --max-delete=NUM        don't delete more than NUM files
197 @@ -695,6 +696,11 @@ receiving side that are not on the sendi
198  delete any files on the receiving side that are excluded (see --exclude).
199  Implies --delete.
200  
201 +dit(bf(--delete-sent-files)) This tells rsync to remove the source files
202 +on the sending side that are successfully transferred to the receiving
203 +side.  Directories are not removed, nor are files that are identical on
204 +both systems.
205 +
206  dit(bf(--ignore-errors)) Tells --delete to go ahead and delete files
207  even when there are I/O errors.
208  
209 --- orig/sender.c       2005-01-17 23:11:46
210 +++ sender.c    2004-07-26 16:49:19
211 @@ -26,6 +26,7 @@ extern int io_error;
212  extern int dry_run;
213  extern int am_server;
214  extern int am_daemon;
215 +extern int delete_sent_files;
216  extern int protocol_version;
217  extern int updating_basis_file;
218  extern int make_backups;
219 @@ -94,7 +95,29 @@ static struct sum_struct *receive_sums(i
220         return s;
221  }
222  
223 +static struct file_list *the_flist;
224  
225 +void successful_send(int i)
226 +{
227 +       char fname[MAXPATHLEN];
228 +       struct file_struct *file;
229 +       unsigned int offset;
230 +
231 +       if (!the_flist || i < 0 || i >= the_flist->count)
232 +               return;
233 +
234 +       file = the_flist->files[i];
235 +       if (!(file->flags & FLAG_SENT))
236 +               return; /* We didn't send it -- impossible! */
237 +       if (file->basedir) {
238 +               offset = stringjoin(fname, sizeof fname,
239 +                                   file->basedir, "/", NULL);
240 +       } else
241 +               offset = 0;
242 +       f_name_to(file, fname + offset);
243 +       if (delete_sent_files && do_unlink(fname) == 0 && verbose > 0)
244 +               rprintf(FINFO, "sender removed %s\n", fname + offset);
245 +}
246  
247  void send_files(struct file_list *flist, int f_out, int f_in)
248  {
249 @@ -113,6 +136,8 @@ void send_files(struct file_list *flist,
250         if (verbose > 2)
251                 rprintf(FINFO, "send_files starting\n");
252  
253 +       the_flist = flist;
254 +
255         while (1) {
256                 unsigned int offset;
257  
258 @@ -248,6 +273,9 @@ void send_files(struct file_list *flist,
259                         rprintf(FINFO, "sender finished %s\n",
260                                 safe_fname(fname));
261                 }
262 +
263 +               /* Flag that we actually sent this entry. */
264 +               file->flags |= FLAG_SENT;
265         }
266         make_backups = save_make_backups;
267