Fixed failing hunks.
[rsync.git/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   2004-11-25 16:32:40
8 +++ io.c        2004-07-03 20:17:10
9 @@ -243,6 +243,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 @@ -676,6 +684,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 2004-11-27 17:53:24
42 +++ main.c      2004-08-13 08:24:23
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;
49  extern int copy_links;
50  extern int keep_dirlinks;
51 @@ -648,6 +649,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 @@ -732,6 +735,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      2004-11-27 17:53:24
71 +++ options.c   2004-11-27 18:04:22
72 @@ -88,8 +88,10 @@ int daemon_bwlimit = 0;
73  int bwlimit = 0;
74  size_t bwlimit_writemax = 0;
75  int delete_after = 0;
76 +int delete_sent_files = 0;
77  int only_existing = 0;
78  int opt_ignore_existing = 0;
79 +int need_messages_from_generator = 0;
80  int max_delete = 0;
81  OFF_T max_size = 0;
82  int ignore_errors = 0;
83 @@ -273,6 +275,7 @@ void usage(enum logcode F)
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,"     --max-size=SIZE         don't transfer any file larger than SIZE\n");
91 @@ -319,7 +322,7 @@ void usage(enum logcode F)
92  }
93  
94  enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
95 -      OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED,
96 +      OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_DELETE_SENT_FILES,
97        OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST,
98        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
99        OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE,
100 @@ -340,6 +343,7 @@ static struct poptOption long_options[] 
101    {"ignore-existing",  0,  POPT_ARG_NONE,   &opt_ignore_existing, 0, 0, 0 },
102    {"delete-after",     0,  POPT_ARG_NONE,   0, OPT_DELETE_AFTER, 0, 0 },
103    {"delete-excluded",  0,  POPT_ARG_NONE,   0, OPT_DELETE_EXCLUDED, 0, 0 },
104 +  {"delete-sent-files",0,  POPT_ARG_NONE,   0, OPT_DELETE_SENT_FILES, 0, 0 },
105    {"force",            0,  POPT_ARG_NONE,   &force_delete, 0, 0, 0 },
106    {"numeric-ids",      0,  POPT_ARG_NONE,   &numeric_ids, 0, 0, 0 },
107    {"exclude",          0,  POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
108 @@ -621,6 +625,11 @@ int parse_arguments(int *argc, const cha
109                         delete_mode = 1;
110                         break;
111  
112 +               case OPT_DELETE_SENT_FILES:
113 +                       delete_sent_files = 1;
114 +                       need_messages_from_generator = 1;
115 +                       break;
116 +
117                 case OPT_EXCLUDE:
118                         add_exclude(&exclude_list, poptGetOptArg(pc), 0);
119                         break;
120 @@ -1237,6 +1246,9 @@ void server_options(char **args,int *arg
121                 }
122         }
123  
124 +       if (delete_sent_files)
125 +               args[ac++] = "--delete-sent-files";
126 +
127         *argc = ac;
128         return;
129  
130 --- orig/receiver.c     2004-11-27 17:57:31
131 +++ receiver.c  2004-08-13 08:38:51
132 @@ -46,6 +46,7 @@ extern char *backup_dir;
133  extern char *backup_suffix;
134  extern int backup_suffix_len;
135  extern int cleanup_got_literal;
136 +extern int delete_sent_files;
137  extern int module_id;
138  extern int ignore_errors;
139  extern int orig_umask;
140 @@ -339,7 +340,7 @@ int recv_files(int f_in, struct file_lis
141         char *fname, fbuf[MAXPATHLEN];
142         char template[MAXPATHLEN];
143         char fnametmp[MAXPATHLEN];
144 -       char *fnamecmp, *partialptr;
145 +       char *fnamecmp, *partialptr, numbuf[4];
146         char fnamecmpbuf[MAXPATHLEN];
147         struct file_struct *file;
148         struct stats initial_stats;
149 @@ -580,7 +581,12 @@ int recv_files(int f_in, struct file_lis
150  
151                 cleanup_disable();
152  
153 -               if (!recv_ok) {
154 +               if (recv_ok) {
155 +                       if (delete_sent_files) {
156 +                               SIVAL(numbuf, 0, i);
157 +                               send_msg(MSG_SUCCESS, numbuf, 4);
158 +                       }
159 +               } else {
160                         int msgtype = csum_length == SUM_LENGTH || read_batch ?
161                                 FERROR : FINFO;
162                         if (msgtype == FERROR || verbose) {
163 @@ -604,9 +610,8 @@ int recv_files(int f_in, struct file_lis
164                                         keptstr, redostr);
165                         }
166                         if (csum_length != SUM_LENGTH) {
167 -                               char buf[4];
168 -                               SIVAL(buf, 0, i);
169 -                               send_msg(MSG_REDO, buf, 4);
170 +                               SIVAL(numbuf, 0, i);
171 +                               send_msg(MSG_REDO, numbuf, 4);
172                         }
173                 }
174         }
175 --- orig/rsync.h        2004-11-27 17:53:24
176 +++ rsync.h     2004-07-03 20:17:10
177 @@ -60,6 +60,7 @@
178  #define FLAG_TOP_DIR (1<<0)
179  #define FLAG_HLINK_EOL (1<<1)  /* generator only */
180  #define FLAG_MOUNT_POINT (1<<2)        /* sender only */
181 +#define FLAG_SENT (1<<7)       /* sender only */
182  
183  /* update this if you make incompatible changes */
184  #define PROTOCOL_VERSION 28
185 @@ -134,6 +135,7 @@ enum logcode { FERROR=1, FINFO=2, FLOG=3
186  /* Messages types that are sent over the message channel.  The logcode
187   * values must all be present here with identical numbers. */
188  enum msgcode {
189 +       MSG_SUCCESS=6,  /* successfully updated indicated flist index */
190         MSG_DONE=5,     /* current phase is done */
191         MSG_REDO=4,     /* reprocess indicated flist index */
192         MSG_ERROR=FERROR, MSG_INFO=FINFO, MSG_LOG=FLOG, /* remote logging */
193 --- orig/rsync.yo       2004-11-27 17:53:24
194 +++ rsync.yo    2004-07-03 20:17:10
195 @@ -343,6 +343,7 @@ verb(
196       --delete                delete files that don't exist on sender
197       --delete-excluded       also delete excluded files on receiver
198       --delete-after          receiver deletes after transfer, not before
199 +     --delete-sent-files     updated/sent files are removed from sender
200       --ignore-errors         delete even if there are I/O errors
201       --max-delete=NUM        don't delete more than NUM files
202       --max-size=SIZE         don't transfer any file larger than SIZE
203 @@ -675,6 +676,11 @@ receiving side before transferring files
204  sufficient space on the receiving filesystem. If you want to delete
205  after transferring, use the --delete-after switch. Implies --delete.
206  
207 +dit(bf(--delete-sent-files)) This tells rsync to remove the source files
208 +on the sending side that are successfully transferred to the receiving
209 +side.  Directories are not removed, nor are files that are identical on
210 +both systems.
211 +
212  dit(bf(--ignore-errors)) Tells --delete to go ahead and delete files
213  even when there are I/O errors.
214  
215 --- orig/sender.c       2004-09-20 05:10:48
216 +++ sender.c    2004-07-26 16:49:19
217 @@ -26,6 +26,7 @@ extern int io_error;
218  extern int dry_run;
219  extern int am_server;
220  extern int am_daemon;
221 +extern int delete_sent_files;
222  extern int protocol_version;
223  extern int make_backups;
224  extern struct stats stats;
225 @@ -108,7 +109,29 @@ static struct sum_struct *receive_sums(i
226         return s;
227  }
228  
229 +static struct file_list *the_flist;
230  
231 +void successful_send(int i)
232 +{
233 +       char fname[MAXPATHLEN];
234 +       struct file_struct *file;
235 +       unsigned int offset;
236 +
237 +       if (!the_flist)
238 +               return;
239 +
240 +       file = the_flist->files[i];
241 +       if (!(file->flags & FLAG_SENT))
242 +               return; /* We didn't send it -- impossible! */
243 +       if (file->basedir) {
244 +               offset = stringjoin(fname, sizeof fname,
245 +                                   file->basedir, "/", NULL);
246 +       } else
247 +               offset = 0;
248 +       f_name_to(file, fname + offset);
249 +       if (delete_sent_files && do_unlink(fname) == 0 && verbose > 0)
250 +               rprintf(FINFO, "sender removed %s\n", fname + offset);
251 +}
252  
253  void send_files(struct file_list *flist, int f_out, int f_in)
254  {
255 @@ -127,6 +150,8 @@ void send_files(struct file_list *flist,
256         if (verbose > 2)
257                 rprintf(FINFO, "send_files starting\n");
258  
259 +       the_flist = flist;
260 +
261         while (1) {
262                 unsigned int offset;
263  
264 @@ -257,6 +282,9 @@ void send_files(struct file_list *flist,
265                         rprintf(FINFO, "sender finished %s\n",
266                                 safe_fname(fname));
267                 }
268 +
269 +               /* Flag that we actually sent this entry. */
270 +               file->flags |= FLAG_SENT;
271         }
272         make_backups = save_make_backups;
273