Use do_ftruncate() for the added call too.
[rsync-patches.git] / checksum-reading.diff
index 3e8748d8e7c7168ce0dc033015cb39b043e8a0f6..8fcb3541981ef6e2e784af3ecda0c5e03f72c9d4 100644 (file)
@@ -16,7 +16,7 @@ To use this patch, run these commands for a successful build:
     ./configure                               (optional if already run)
     make
 
-based-on: 3b8f8192227b14e708bf535072485e50f4362270
+based-on: d64bda1c1e79dc385f194d74f7957ce7cd118654
 diff --git a/checksum.c b/checksum.c
 --- a/checksum.c
 +++ b/checksum.c
@@ -41,7 +41,7 @@ diff --git a/clientserver.c b/clientserver.c
  extern int io_timeout;
  extern int no_detach;
  extern int write_batch;
-@@ -871,6 +873,9 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
+@@ -879,6 +881,9 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
        } else if (am_root < 0) /* Treat --fake-super from client as --super. */
                am_root = 2;
  
@@ -78,7 +78,7 @@ diff --git a/flist.c b/flist.c
  extern int copy_links;
  extern int copy_unsafe_links;
  extern int protocol_version;
-@@ -71,6 +74,7 @@ extern int sender_symlink_iconv;
+@@ -72,6 +75,7 @@ extern int sender_symlink_iconv;
  extern int output_needs_newline;
  extern int sender_keeps_checksum;
  extern int unsort_ndx;
@@ -86,7 +86,7 @@ diff --git a/flist.c b/flist.c
  extern struct stats stats;
  extern char *filesfrom_host;
  extern char *usermap, *groupmap;
-@@ -95,6 +99,12 @@ extern iconv_t ic_send, ic_recv;
+@@ -96,6 +100,12 @@ extern iconv_t ic_send, ic_recv;
  #endif
  #endif
  
@@ -99,7 +99,7 @@ diff --git a/flist.c b/flist.c
  #define PTR_SIZE (sizeof (struct file_struct *))
  
  int io_error;
-@@ -136,7 +146,11 @@ static char tmp_sum[MAX_DIGEST_LEN];
+@@ -137,7 +147,11 @@ static char tmp_sum[MAX_DIGEST_LEN];
  static char empty_sum[MAX_DIGEST_LEN];
  static int flist_count_offset; /* for --delete --progress */
  
@@ -112,7 +112,7 @@ diff --git a/flist.c b/flist.c
  static void output_flist(struct file_list *flist);
  
  void init_flist(void)
-@@ -351,6 +365,238 @@ static void flist_done_allocating(struct file_list *flist)
+@@ -352,6 +366,238 @@ static void flist_done_allocating(struct file_list *flist)
                flist->pool_boundary = ptr;
  }
  
@@ -351,7 +351,7 @@ diff --git a/flist.c b/flist.c
  /* Call this with EITHER (1) "file, NULL, 0" to chdir() to the file's
   * F_PATHNAME(), or (2) "NULL, dir, dirlen" to chdir() to the supplied dir,
   * with dir == NULL taken to be the starting directory, and dirlen < 0
-@@ -1142,7 +1388,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+@@ -1145,7 +1391,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
                              STRUCT_STAT *stp, int flags, int filter_level)
  {
        static char *lastdir;
@@ -360,7 +360,7 @@ diff --git a/flist.c b/flist.c
        struct file_struct *file;
        char thisname[MAXPATHLEN];
        char linkname[MAXPATHLEN];
-@@ -1288,9 +1534,16 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+@@ -1291,9 +1537,16 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
                        memcpy(lastdir, thisname, len);
                        lastdir[len] = '\0';
                        lastdir_len = len;
@@ -378,7 +378,7 @@ diff --git a/flist.c b/flist.c
        basename_len = strlen(basename) + 1; /* count the '\0' */
  
  #ifdef SUPPORT_LINKS
-@@ -1308,11 +1561,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+@@ -1311,11 +1564,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
                extra_len += EXTRA_LEN;
  #endif
  
@@ -392,7 +392,7 @@ diff --git a/flist.c b/flist.c
  
  #if EXTRA_ROUNDING > 0
        if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
-@@ -1395,8 +1645,14 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+@@ -1398,8 +1648,14 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
                return NULL;
        }
  
@@ -409,7 +409,7 @@ diff --git a/flist.c b/flist.c
  
        if (unsort_ndx)
                F_NDX(file) = stats.num_dirs;
-@@ -2518,7 +2774,7 @@ struct file_list *recv_file_list(int f)
+@@ -2550,7 +2806,7 @@ struct file_list *recv_file_list(int f)
                        rprintf(FINFO, "[%s] flist_eof=1\n", who_am_i());
        }
  
@@ -418,7 +418,7 @@ diff --git a/flist.c b/flist.c
  
        if (protocol_version < 30) {
                /* Recv the io_error flag */
-@@ -2741,7 +2997,7 @@ void flist_free(struct file_list *flist)
+@@ -2773,7 +3029,7 @@ void flist_free(struct file_list *flist)
  
  /* This routine ensures we don't have any duplicate names in our file list.
   * duplicate names can cause corruption because of the pipelining. */
@@ -427,7 +427,7 @@ diff --git a/flist.c b/flist.c
  {
        char fbuf[MAXPATHLEN];
        int i, prev_i;
-@@ -2792,7 +3048,7 @@ static void flist_sort_and_clean(struct file_list *flist, int strip_root)
+@@ -2824,7 +3080,7 @@ static void flist_sort_and_clean(struct file_list *flist, int strip_root)
                        /* If one is a dir and the other is not, we want to
                         * keep the dir because it might have contents in the
                         * list.  Otherwise keep the first one. */
@@ -436,7 +436,7 @@ diff --git a/flist.c b/flist.c
                                struct file_struct *fp = flist->sorted[j];
                                if (!S_ISDIR(fp->mode))
                                        keep = i, drop = j;
-@@ -2808,8 +3064,8 @@ static void flist_sort_and_clean(struct file_list *flist, int strip_root)
+@@ -2840,8 +3096,8 @@ static void flist_sort_and_clean(struct file_list *flist, int strip_root)
                        } else
                                keep = j, drop = i;
  
@@ -447,7 +447,7 @@ diff --git a/flist.c b/flist.c
                                        rprintf(FINFO,
                                            "removing duplicate name %s from file list (%d)\n",
                                            f_name(file, fbuf), drop + flist->ndx_start);
-@@ -2831,7 +3087,7 @@ static void flist_sort_and_clean(struct file_list *flist, int strip_root)
+@@ -2863,7 +3119,7 @@ static void flist_sort_and_clean(struct file_list *flist, int strip_root)
        }
        flist->high = prev_i;
  
@@ -467,7 +467,7 @@ diff --git a/generator.c b/generator.c
  extern int remove_source_files;
  extern int delay_updates;
  extern int update_only;
-@@ -523,7 +524,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
+@@ -515,7 +516,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
  
  
  /* Perform our quick-check heuristic for determining if a file is unchanged. */
@@ -476,7 +476,7 @@ diff --git a/generator.c b/generator.c
  {
        if (st->st_size != F_LENGTH(file))
                return 0;
-@@ -532,7 +533,10 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
+@@ -524,7 +525,10 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
           of the file time to determine whether to sync */
        if (always_checksum > 0 && S_ISREG(st->st_mode)) {
                char sum[MAX_DIGEST_LEN];
@@ -488,7 +488,7 @@ diff --git a/generator.c b/generator.c
                return memcmp(sum, F_SUM(file), checksum_len) == 0;
        }
  
-@@ -796,7 +800,7 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
+@@ -794,7 +798,7 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
                        match_level = 1;
                        /* FALL THROUGH */
                case 1:
@@ -497,7 +497,7 @@ diff --git a/generator.c b/generator.c
                                continue;
                        best_match = j;
                        match_level = 2;
-@@ -1082,7 +1086,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
+@@ -1080,7 +1084,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
         * --ignore-non-existing, daemon exclude, or mkdir failure. */
        static struct file_struct *skip_dir = NULL;
        static struct file_list *fuzzy_dirlist = NULL;
@@ -506,7 +506,7 @@ diff --git a/generator.c b/generator.c
        struct file_struct *fuzzy_file = NULL;
        int fd = -1, f_copy = -1;
        stat_x sx, real_sx;
-@@ -1166,8 +1170,8 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
+@@ -1164,8 +1168,8 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                                flist_free(fuzzy_dirlist);
                                fuzzy_dirlist = NULL;
                        }
@@ -517,7 +517,7 @@ diff --git a/generator.c b/generator.c
  #ifdef SUPPORT_ACLS
                        if (!preserve_perms)
                                dflt_perms = default_perms_for_dir(dn);
-@@ -1175,10 +1179,15 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
+@@ -1173,10 +1177,15 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                }
                parent_dirname = dn;
  
@@ -537,7 +537,7 @@ diff --git a/generator.c b/generator.c
                }
  
                statret = link_stat(fname, &sx.st, keep_dirlinks && is_dir);
-@@ -1601,7 +1610,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
+@@ -1602,7 +1611,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                ;
        else if (fnamecmp_type == FNAMECMP_FUZZY)
                ;
@@ -634,7 +634,7 @@ diff --git a/options.c b/options.c
  int max_delete = INT_MIN;
  OFF_T max_size = 0;
  OFF_T min_size = 0;
-@@ -662,6 +663,7 @@ void usage(enum logcode F)
+@@ -663,6 +664,7 @@ void usage(enum logcode F)
    rprintf(F," -q, --quiet                 suppress non-error messages\n");
    rprintf(F,"     --no-motd               suppress daemon-mode MOTD (see manpage caveat)\n");
    rprintf(F," -c, --checksum              skip based on checksum, not mod-time & size\n");
@@ -642,16 +642,16 @@ diff --git a/options.c b/options.c
    rprintf(F," -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)\n");
    rprintf(F,"     --no-OPTION             turn off an implied OPTION (e.g. --no-D)\n");
    rprintf(F," -r, --recursive             recurse into directories\n");
-@@ -799,7 +801,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
+@@ -800,7 +802,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
+       OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
        OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
-       OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, OPT_INFO, OPT_DEBUG,
--      OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN,
-+      OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN, OPT_SUMFILES,
+-      OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, OPT_INFO, OPT_DEBUG,
++      OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, OPT_INFO, OPT_DEBUG, OPT_SUMFILES,
+       OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN, OPT_BWLIMIT,
        OPT_SERVER, OPT_REFUSED_BASE = 9000};
  
- static struct poptOption long_options[] = {
-@@ -934,6 +936,7 @@ static struct poptOption long_options[] = {
+@@ -939,6 +941,7 @@ static struct poptOption long_options[] = {
    {"checksum",        'c', POPT_ARG_VAL,    &always_checksum, 1, 0, 0 },
    {"no-checksum",      0,  POPT_ARG_VAL,    &always_checksum, 0, 0, 0 },
    {"no-c",             0,  POPT_ARG_VAL,    &always_checksum, 0, 0, 0 },
@@ -659,7 +659,7 @@ diff --git a/options.c b/options.c
    {"block-size",      'B', POPT_ARG_LONG,   &block_size, 0, 0, 0 },
    {"compare-dest",     0,  POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
    {"copy-dest",        0,  POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
-@@ -1632,6 +1635,23 @@ int parse_arguments(int *argc_p, const char ***argv_p)
+@@ -1657,6 +1660,23 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        }
                        break;
  
@@ -683,7 +683,7 @@ diff --git a/options.c b/options.c
                case OPT_INFO:
                        arg = poptGetOptArg(pc);
                        parse_output_words(info_words, info_levels, arg, USER_PRIORITY);
-@@ -1832,6 +1852,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
+@@ -1871,6 +1891,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
        }
  #endif
  
@@ -696,7 +696,7 @@ diff --git a/options.c b/options.c
 diff --git a/rsync.h b/rsync.h
 --- a/rsync.h
 +++ b/rsync.h
-@@ -723,6 +723,10 @@ extern int xattrs_ndx;
+@@ -733,6 +733,10 @@ extern int xattrs_ndx;
  #define F_SUM(f) ((char*)OPT_EXTRA(f, START_BUMP(f) + HLINK_BUMP(f) \
                                    + SUM_EXTRA_CNT - 1))
  
@@ -707,7 +707,7 @@ diff --git a/rsync.h b/rsync.h
  /* Some utility defines: */
  #define F_IS_ACTIVE(f) (f)->basename[0]
  #define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED)
-@@ -911,6 +915,13 @@ typedef struct {
+@@ -929,6 +933,13 @@ typedef struct {
        char fname[1]; /* has variable size */
  } relnamecache;
  
@@ -732,7 +732,7 @@ diff --git a/rsync.yo b/rsync.yo
   -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
       --no-OPTION             turn off an implied OPTION (e.g. --no-D)
   -r, --recursive             recurse into directories
-@@ -568,9 +569,9 @@ uses a "quick check" that (by default) checks if each file's size and time
+@@ -569,9 +570,9 @@ uses a "quick check" that (by default) checks if each file's size and time
  of last modification match between the sender and receiver.  This option
  changes this to compare a 128-bit checksum for each file that has a
  matching size.  Generating the checksums means that both sides will expend
@@ -745,7 +745,7 @@ diff --git a/rsync.yo b/rsync.yo
  
  The sending side generates its checksums while it is doing the file-system
  scan that builds the list of the available files.  The receiver generates
-@@ -578,6 +579,8 @@ its checksums when it is scanning for changed files, and will checksum any
+@@ -579,6 +580,8 @@ its checksums when it is scanning for changed files, and will checksum any
  file that has the same size as the corresponding sender's file:  files with
  either a changed size or a changed checksum are selected for transfer.
  
@@ -754,7 +754,7 @@ diff --git a/rsync.yo b/rsync.yo
  Note that rsync always verifies that each em(transferred) file was
  correctly reconstructed on the receiving side by checking a whole-file
  checksum that is generated as the file is transferred, but that
-@@ -587,6 +590,36 @@ option's before-the-transfer "Does this file need to be updated?" check.
+@@ -588,6 +591,36 @@ option's before-the-transfer "Does this file need to be updated?" check.
  For protocol 30 and beyond (first supported in 3.0.0), the checksum used is
  MD5.  For older protocols, the checksum used is MD4.
  
@@ -794,7 +794,7 @@ diff --git a/rsync.yo b/rsync.yo
 diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo
 --- a/rsyncd.conf.yo
 +++ b/rsyncd.conf.yo
-@@ -312,6 +312,17 @@ locking on this file to ensure that the max connections limit is not
+@@ -314,6 +314,17 @@ locking on this file to ensure that the max connections limit is not
  exceeded for the modules sharing the lock file.
  The default is tt(/var/run/rsyncd.lock).