Changed the code that cleans up the old nightly releases from
[rsync/rsync.git] / generator.c
index ed31eac..f0a752b 100644 (file)
@@ -4,12 +4,11 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003, 2004, 2005, 2006, 2007 Wayne Davison
+ * Copyright (C) 2003-2007 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -557,7 +556,7 @@ void itemize(struct file_struct *file, int ndx, int statret,
          || stdout_format_has_i > 1 || (xname && *xname)) && !read_batch) {
                if (protocol_version >= 29) {
                        if (ndx >= 0)
-                               write_ndx(sock_f_out, ndx + cur_flist->ndx_start);
+                               write_ndx(sock_f_out, ndx);
                        write_shortint(sock_f_out, iflags);
                        if (iflags & ITEM_BASIS_TYPE_FOLLOWS)
                                write_byte(sock_f_out, fnamecmp_type);
@@ -1025,11 +1024,11 @@ static int try_dests_non(struct file_struct *file, char *fname, int ndx,
 
 static int phase = 0;
 
-/* Acts on cur_flist->file's ndx'th item, whose name is fname.  If a dir,
+/* Acts on the indicated item in cur_flist whose name is fname.  If a dir,
  * make sure it exists, and has the right permissions/timestamp info.  For
  * all other non-regular files (symlinks, etc.) we create them here.  For
  * regular files that have changed, we try to find a basis file and then
- * start sending checksums.
+ * start sending checksums.  The ndx is the file's unique index value.
  *
  * When fname is non-null, it must point to a MAXPATHLEN buffer!
  *
@@ -1144,14 +1143,6 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                return;
        }
 
-       /* If we're not preserving permissions, change the file-list's
-        * mode based on the local permissions and some heuristics. */
-       if (!preserve_perms) {
-               int exists = statret == 0
-                         && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
-               file->mode = dest_mode(file->mode, st.st_mode, exists);
-       }
-
        if (S_ISDIR(file->mode)) {
                /* The file to be received is a directory, so we need
                 * to prepare appropriately.  If there is already a
@@ -1174,6 +1165,10 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                                statret = -1;
                        new_root_dir = 0;
                }
+               if (!preserve_perms) { /* See comment in non-dir code below. */
+                       file->mode = dest_mode(file->mode, st.st_mode,
+                                              statret == 0);
+               }
                if (statret != 0 && basis_dir[0] != NULL) {
                        int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
                                              itemizing, code);
@@ -1219,6 +1214,13 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                return;
        }
 
+       /* If we're not preserving permissions, change the file-list's
+        * mode based on the local permissions and some heuristics. */
+       if (!preserve_perms) {
+               int exists = statret == 0 && !S_ISDIR(st.st_mode);
+               file->mode = dest_mode(file->mode, st.st_mode, exists);
+       }
+
 #ifdef SUPPORT_HARD_LINKS
        if (preserve_hard_links && F_HLINK_NOT_FIRST(file)
         && hard_link_check(file, ndx, fname, statret, &st, itemizing, code))
@@ -1509,7 +1511,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                        return;
          return_with_success:
                if (!dry_run)
-                       send_msg_int(MSG_SUCCESS, ndx + cur_flist->ndx_start);
+                       send_msg_int(MSG_SUCCESS, ndx);
                return;
        }
 
@@ -1590,7 +1592,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
        if (preserve_hard_links && F_IS_HLINKED(file))
                file->flags |= FLAG_FILE_SENT;
 #endif
-       write_ndx(f_out, ndx + cur_flist->ndx_start);
+       write_ndx(f_out, ndx);
        if (itemizing) {
                int iflags = ITEM_TRANSFER;
                if (always_checksum > 0)
@@ -1662,7 +1664,7 @@ static void touch_up_dirs(struct file_list *flist, int ndx)
                if (allowed_lull && !(++j % lull_mod))
                        maybe_send_keepalive();
                else if (!(j % 200))
-                       maybe_flush_socket();
+                       maybe_flush_socket(0);
        }
 }
 
@@ -1698,9 +1700,8 @@ void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
 
                flist = cur_flist;
                cur_flist = flist_for_ndx(ndx);
-               ndx -= cur_flist->ndx_start;
 
-               file = cur_flist->files[ndx];
+               file = cur_flist->files[ndx - cur_flist->ndx_start];
                if (solo_file)
                        strlcpy(fbuf, solo_file, sizeof fbuf);
                else
@@ -1727,8 +1728,10 @@ void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
                if (first_flist->in_progress || first_flist->to_redo)
                        break;
 
-               if (!read_batch)
+               if (!read_batch) {
                        write_ndx(sock_f_out, NDX_DONE);
+                       maybe_flush_socket(1);
+               }
 
                if (delete_during == 2 || !dir_tweaking) {
                        /* Skip directory touch-up. */
@@ -1823,7 +1826,8 @@ void generate_files(int f_out, const char *local_name)
                                strlcpy(fbuf, solo_file, sizeof fbuf);
                        else
                                f_name(file, fbuf);
-                       recv_generator(fbuf, file, i, itemizing, code, f_out);
+                       recv_generator(fbuf, file, i + cur_flist->ndx_start,
+                                      itemizing, code, f_out);
 
                        /* We need to ensure that any dirs we create have
                         * writeable permissions during the time we are putting
@@ -1848,7 +1852,7 @@ void generate_files(int f_out, const char *local_name)
                        if (allowed_lull && !(i % lull_mod))
                                maybe_send_keepalive();
                        else if (!(i % 200))
-                               maybe_flush_socket();
+                               maybe_flush_socket(0);
                }
 
                if (!inc_recurse) {