Use do_ftruncate() for the added call too.
[rsync-patches.git] / db.diff
diff --git a/db.diff b/db.diff
index 1eed1eb2cb94d85fdeb4298ff05d5c6b8b75ef51..65d138c6ab7e643c25439305c115b6e45c504bf6 100644 (file)
--- a/db.diff
+++ b/db.diff
@@ -19,17 +19,17 @@ is used.  Future improvements may include:
 
 To use this patch, run these commands for a successful build:
 
-    patch -p1 <patches/remote-option.diff
     patch -p1 <patches/db.diff
     ./configure                               (optional if already run)
     make
 
+based-on: d64bda1c1e79dc385f194d74f7957ce7cd118654
 diff --git a/Makefile.in b/Makefile.in
 --- a/Makefile.in
 +++ b/Makefile.in
-@@ -35,7 +35,7 @@ ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
+@@ -36,7 +36,7 @@ ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
  OBJS1=flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o \
-       util.o main.o checksum.o match.o syscall.o log.o backup.o
+       util.o main.o checksum.o match.o syscall.o log.o backup.o delete.o
  OBJS2=options.o io.o compat.o hlink.o token.o uidlist.o socket.o hashtable.o \
 -      fileio.o batch.o clientname.o chmod.o acls.o xattrs.o
 +      fileio.o batch.o clientname.o chmod.o db.o acls.o xattrs.o
@@ -45,9 +45,9 @@ diff --git a/checksum.c b/checksum.c
  extern int protocol_version;
 +extern int use_db;
  
- int csum_length = SHORT_SUM_LENGTH; /* initial value */
-@@ -100,10 +101,10 @@ void get_checksum2(char *buf, int32 len, char *sum)
+ /*
+   a simple 32 bit checksum that can be upadted from either end
+@@ -98,10 +99,10 @@ void get_checksum2(char *buf, int32 len, char *sum)
        }
  }
  
@@ -60,7 +60,7 @@ diff --git a/checksum.c b/checksum.c
        md_context m;
        int32 remainder;
        int fd;
-@@ -114,7 +115,7 @@ void file_checksum(char *fname, char *sum, OFF_T size)
+@@ -112,7 +113,7 @@ void file_checksum(char *fname, char *sum, OFF_T size)
        if (fd == -1)
                return;
  
@@ -69,7 +69,7 @@ diff --git a/checksum.c b/checksum.c
  
        if (protocol_version >= 30) {
                md5_begin(&m);
-@@ -148,6 +149,9 @@ void file_checksum(char *fname, char *sum, OFF_T size)
+@@ -146,6 +147,9 @@ void file_checksum(char *fname, char *sum, OFF_T size)
                mdfour_result(&m, (uchar *)sum);
        }
  
@@ -82,17 +82,17 @@ diff --git a/checksum.c b/checksum.c
 diff --git a/cleanup.c b/cleanup.c
 --- a/cleanup.c
 +++ b/cleanup.c
-@@ -27,6 +27,7 @@ extern int am_daemon;
+@@ -26,6 +26,7 @@ extern int am_server;
+ extern int am_daemon;
+ extern int am_receiver;
  extern int io_error;
++extern int use_db;
  extern int keep_partial;
  extern int got_xfer_error;
-+extern int use_db;
- extern char *partial_dir;
- extern char *logfile_name;
-@@ -124,6 +125,12 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
-               /* FALLTHROUGH */
+ extern int protocol_version;
+@@ -142,6 +143,12 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
  #include "case_N.h"
+               switch_step++;
  
 +              if (use_db)
 +                      db_disconnect();
@@ -106,7 +106,7 @@ diff --git a/cleanup.c b/cleanup.c
 diff --git a/clientserver.c b/clientserver.c
 --- a/clientserver.c
 +++ b/clientserver.c
-@@ -42,13 +42,16 @@ extern int numeric_ids;
+@@ -42,12 +42,15 @@ extern int numeric_ids;
  extern int filesfrom_fd;
  extern int remote_protocol;
  extern int protocol_version;
@@ -118,12 +118,11 @@ diff --git a/clientserver.c b/clientserver.c
  extern int default_af_hint;
  extern int logfile_format_has_i;
  extern int logfile_format_has_o_or_i;
- extern mode_t orig_umask;
 +extern char *db_config;
  extern char *bind_address;
- extern char *sockopts;
  extern char *config_file;
-@@ -552,6 +555,9 @@ static int rsync_module(int f_in, int f_out, int i, char *addr, char *host)
+ extern char *logfile_format;
+@@ -671,6 +674,9 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
  
        log_init(1);
  
@@ -132,8 +131,8 @@ diff --git a/clientserver.c b/clientserver.c
 +
  #ifdef HAVE_PUTENV
        if (*lp_prexfer_exec(i) || *lp_postxfer_exec(i)) {
-               char *modname, *modpath, *hostaddr, *hostname, *username;
-@@ -768,6 +774,10 @@ static int rsync_module(int f_in, int f_out, int i, char *addr, char *host)
+               int status;
+@@ -867,6 +873,10 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
  
        am_server = 1; /* Don't let someone try to be tricky. */
        quiet = 0;
@@ -144,10 +143,10 @@ diff --git a/clientserver.c b/clientserver.c
        if (lp_ignore_errors(module_id))
                ignore_errors = 1;
        if (write_batch < 0)
-diff --git a/configure.in b/configure.in
---- a/configure.in
-+++ b/configure.in
-@@ -314,7 +314,7 @@ AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h \
+diff --git a/configure.ac b/configure.ac
+--- a/configure.ac
++++ b/configure.ac
+@@ -337,7 +337,7 @@ AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h \
      sys/un.h sys/attr.h mcheck.h arpa/inet.h arpa/nameser.h locale.h \
      netdb.h malloc.h float.h limits.h iconv.h libcharset.h langinfo.h \
      sys/acl.h acl/libacl.h attr/xattr.h sys/xattr.h sys/extattr.h \
@@ -156,7 +155,7 @@ diff --git a/configure.in b/configure.in
  AC_HEADER_MAJOR
  
  AC_CACHE_CHECK([if makedev takes 3 args],rsync_cv_MAKEDEV_TAKES_3_ARGS,[
-@@ -969,6 +969,29 @@ if test x"$enable_acl_support" = x"no" -o x"$enable_xattr_support" = x"no" -o x"
+@@ -1019,6 +1019,29 @@ if test x"$enable_acl_support" = x"no" -o x"$enable_xattr_support" = x"no" -o x"
      fi
  fi
  
@@ -190,7 +189,7 @@ diff --git a/db.c b/db.c
 new file mode 100644
 --- /dev/null
 +++ b/db.c
-@@ -0,0 +1,566 @@
+@@ -0,0 +1,567 @@
 +/*
 + * Routines to access extended file info via DB.
 + *
@@ -212,6 +211,7 @@ new file mode 100644
 +
 +#include "rsync.h"
 +#include "ifuncs.h"
++#include "itypes.h"
 +
 +#if defined HAVE_MYSQL_MYSQL_H && defined HAVE_LIBMYSQLCLIENT
 +#define USE_MYSQL
@@ -760,35 +760,44 @@ new file mode 100644
 diff --git a/flist.c b/flist.c
 --- a/flist.c
 +++ b/flist.c
-@@ -54,6 +54,7 @@ extern int preserve_devices;
- extern int preserve_specials;
+@@ -54,6 +54,7 @@ extern int delete_during;
+ extern int missing_args;
  extern int uid_ndx;
  extern int gid_ndx;
 +extern int use_db;
  extern int eol_nulls;
  extern int relative_paths;
  extern int implied_dirs;
-@@ -1250,14 +1251,16 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
-               memcpy(bp + basename_len, linkname, linkname_len);
+@@ -1311,11 +1312,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+               extra_len += EXTRA_LEN;
  #endif
  
--      if (always_checksum && am_sender && S_ISREG(st.st_mode))
+-      if (always_checksum && am_sender && S_ISREG(st.st_mode)) {
 -              file_checksum(thisname, tmp_sum, st.st_size);
--
-       if (am_sender)
-               F_PATHNAME(file) = pathname;
-       else if (!pool)
-               F_DEPTH(file) = extra_len / EXTRA_LEN;
+-              if (sender_keeps_checksum)
+-                      extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
+-      }
++      if (sender_keeps_checksum && S_ISREG(st.st_mode))
++              extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
  
+ #if EXTRA_ROUNDING > 0
+       if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
+@@ -1398,8 +1396,12 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+               return NULL;
+       }
+-      if (sender_keeps_checksum && S_ISREG(st.st_mode))
+-              memcpy(F_SUM(file), tmp_sum, checksum_len);
 +      if (always_checksum && am_sender && S_ISREG(st.st_mode)) {
 +              if (!use_db || !db_get_checksum(thisname, &st, tmp_sum))
 +                      file_checksum(thisname, &st, tmp_sum);
++              if (sender_keeps_checksum)
++                      memcpy(F_SUM(file), tmp_sum, checksum_len);
 +      }
-+
-       /* This code is only used by the receiver when it is building
-        * a list of files for a delete pass. */
-       if (keep_dirlinks && linkname_len && flist) {
-@@ -1877,6 +1880,9 @@ struct file_list *send_file_list(int f, int argc, char *argv[])
+       if (unsort_ndx)
+               F_NDX(file) = stats.num_dirs;
+@@ -2079,6 +2081,9 @@ struct file_list *send_file_list(int f, int argc, char *argv[])
                     | (eol_nulls || reading_remotely ? RL_EOL_NULLS : 0);
        int implied_dot_dir = 0;
  
@@ -801,7 +810,7 @@ diff --git a/flist.c b/flist.c
 diff --git a/generator.c b/generator.c
 --- a/generator.c
 +++ b/generator.c
-@@ -58,6 +58,7 @@ extern int update_only;
+@@ -60,6 +60,7 @@ extern int human_readable;
  extern int ignore_existing;
  extern int ignore_non_existing;
  extern int inplace;
@@ -809,7 +818,7 @@ diff --git a/generator.c b/generator.c
  extern int append_mode;
  extern int make_backups;
  extern int csum_length;
-@@ -721,7 +722,8 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
+@@ -524,7 +525,8 @@ 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];
@@ -819,20 +828,20 @@ diff --git a/generator.c b/generator.c
                return memcmp(sum, F_SUM(file), checksum_len) == 0;
        }
  
-@@ -2201,6 +2203,9 @@ void generate_files(int f_out, const char *local_name)
+@@ -2078,6 +2080,9 @@ void generate_files(int f_out, const char *local_name)
                        : "enabled");
        }
  
 +      if (use_db && always_checksum)
 +              db_connect();
 +
-       /* Since we often fill up the outgoing socket and then just sit around
-        * waiting for the other 2 processes to do their thing, we don't want
-        * to exit on a timeout.  If the data stops flowing, the receiver will
+       dflt_perms = (ACCESSPERMS & ~orig_umask);
+       do {
 diff --git a/loadparm.c b/loadparm.c
 --- a/loadparm.c
 +++ b/loadparm.c
-@@ -126,6 +126,7 @@ typedef struct
+@@ -108,6 +108,7 @@ typedef struct {
        char *auth_users;
        char *charset;
        char *comment;
@@ -840,7 +849,7 @@ diff --git a/loadparm.c b/loadparm.c
        char *dont_compress;
        char *exclude;
        char *exclude_from;
-@@ -177,6 +178,7 @@ static service sDefault =
+@@ -182,6 +183,7 @@ static const all_vars Defaults = {
   /* auth_users; */            NULL,
   /* charset; */               NULL,
   /* comment; */               NULL,
@@ -848,15 +857,15 @@ diff --git a/loadparm.c b/loadparm.c
   /* dont_compress; */         DEFAULT_DONT_COMPRESS,
   /* exclude; */                       NULL,
   /* exclude_from; */          NULL,
-@@ -307,6 +309,7 @@ static struct parm_struct parm_table[] =
-  {"auth users",        P_STRING, P_LOCAL, &sDefault.auth_users,        NULL,0},
-  {"charset",           P_STRING, P_LOCAL, &sDefault.charset,           NULL,0},
-  {"comment",           P_STRING, P_LOCAL, &sDefault.comment,           NULL,0},
-+ {"db config",         P_STRING, P_LOCAL, &sDefault.db_config,         NULL,0},
-  {"dont compress",     P_STRING, P_LOCAL, &sDefault.dont_compress,     NULL,0},
-  {"exclude from",      P_STRING, P_LOCAL, &sDefault.exclude_from,      NULL,0},
-  {"exclude",           P_STRING, P_LOCAL, &sDefault.exclude,           NULL,0},
-@@ -400,6 +403,7 @@ FN_GLOBAL_INTEGER(lp_rsync_port, &Globals.rsync_port)
+@@ -317,6 +319,7 @@ static struct parm_struct parm_table[] =
+  {"auth users",        P_STRING, P_LOCAL, &Vars.l.auth_users,          NULL,0},
+  {"charset",           P_STRING, P_LOCAL, &Vars.l.charset,             NULL,0},
+  {"comment",           P_STRING, P_LOCAL, &Vars.l.comment,             NULL,0},
++ {"db config",         P_STRING, P_LOCAL, &Vars.l.db_config,           NULL,0},
+  {"dont compress",     P_STRING, P_LOCAL, &Vars.l.dont_compress,       NULL,0},
+  {"exclude from",      P_STRING, P_LOCAL, &Vars.l.exclude_from,        NULL,0},
+  {"exclude",           P_STRING, P_LOCAL, &Vars.l.exclude,             NULL,0},
+@@ -447,6 +450,7 @@ FN_GLOBAL_INTEGER(lp_rsync_port, &Vars.g.rsync_port)
  FN_LOCAL_STRING(lp_auth_users, auth_users)
  FN_LOCAL_STRING(lp_charset, charset)
  FN_LOCAL_STRING(lp_comment, comment)
@@ -867,7 +876,7 @@ diff --git a/loadparm.c b/loadparm.c
 diff --git a/main.c b/main.c
 --- a/main.c
 +++ b/main.c
-@@ -49,6 +49,7 @@ extern int copy_unsafe_links;
+@@ -51,6 +51,7 @@ extern int copy_unsafe_links;
  extern int keep_dirlinks;
  extern int preserve_hard_links;
  extern int protocol_version;
@@ -875,15 +884,15 @@ diff --git a/main.c b/main.c
  extern int file_total;
  extern int recurse;
  extern int xfer_dirs;
-@@ -73,6 +74,7 @@ extern char *partial_dir;
+@@ -82,6 +83,7 @@ extern char *filesfrom_host;
+ extern char *partial_dir;
  extern char *dest_option;
- extern char *basis_dir[];
  extern char *rsync_path;
 +extern char *db_config;
  extern char *shell_cmd;
  extern char *batch_name;
  extern char *password_file;
-@@ -1491,6 +1493,9 @@ int main(int argc,char *argv[])
+@@ -1609,6 +1611,9 @@ int main(int argc,char *argv[])
                exit_cleanup(RERR_SYNTAX);
        }
  
@@ -902,9 +911,9 @@ diff --git a/options.c b/options.c
  char *filesfrom_host = NULL;
 +char *db_config = NULL;
  int eol_nulls = 0;
- int protect_args = 0;
- int human_readable = 0;
-@@ -229,6 +230,7 @@ static void print_rsync_version(enum logcode f)
+ int protect_args = -1;
+ int human_readable = 1;
+@@ -568,6 +569,7 @@ static void print_rsync_version(enum logcode f)
        char const *links = "no ";
        char const *iconv = "no ";
        char const *ipv6 = "no ";
@@ -912,8 +921,8 @@ diff --git a/options.c b/options.c
        STRUCT_STAT *dumstat;
  
  #if SUBPROTOCOL_VERSION != 0
-@@ -261,6 +263,11 @@ static void print_rsync_version(enum logcode f)
- #if defined HAVE_LUTIMES && defined HAVE_UTIMES
+@@ -601,6 +603,11 @@ static void print_rsync_version(enum logcode f)
+ #ifdef CAN_SET_SYMLINK_TIMES
        symtimes = "";
  #endif
 +#if defined HAVE_MYSQL_MYSQL_H && defined HAVE_LIBMYSQLCLIENT
@@ -924,7 +933,7 @@ diff --git a/options.c b/options.c
  
        rprintf(f, "%s  version %s  protocol version %d%s\n",
                RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol);
-@@ -274,8 +281,8 @@ static void print_rsync_version(enum logcode f)
+@@ -614,8 +621,8 @@ static void print_rsync_version(enum logcode f)
                (int)(sizeof (int64) * 8));
        rprintf(f, "    %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
                got_socketpair, hardlinks, links, ipv6, have_inplace);
@@ -935,7 +944,7 @@ diff --git a/options.c b/options.c
  
  #ifdef MAINTAINER_MODE
        rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
-@@ -321,6 +328,7 @@ void usage(enum logcode F)
+@@ -663,6 +670,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");
@@ -943,7 +952,7 @@ 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");
-@@ -579,6 +587,7 @@ static struct poptOption long_options[] = {
+@@ -939,6 +947,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 },
@@ -954,16 +963,16 @@ diff --git a/options.c b/options.c
 diff --git a/pipe.c b/pipe.c
 --- a/pipe.c
 +++ b/pipe.c
-@@ -26,6 +26,9 @@ extern int am_sender;
- extern int am_server;
+@@ -27,6 +27,9 @@ extern int am_server;
  extern int blocking_io;
  extern int filesfrom_fd;
+ extern int munge_symlinks;
 +extern int always_checksum;
 +extern int use_db;
 +extern char *db_config;
- extern mode_t orig_umask;
  extern char *logfile_name;
  extern int remote_option_cnt;
+ extern const char **remote_options;
 @@ -141,6 +144,9 @@ pid_t local_child(int argc, char **argv, int *f_in, int *f_out,
                        logfile_close();
                }
@@ -986,7 +995,7 @@ diff --git a/pipe.c b/pipe.c
 diff --git a/rsync.yo b/rsync.yo
 --- a/rsync.yo
 +++ b/rsync.yo
-@@ -317,6 +317,7 @@ to the detailed description below for a complete description.  verb(
+@@ -323,6 +323,7 @@ to the detailed description below for a complete description.  verb(
   -q, --quiet                 suppress non-error messages
       --no-motd               suppress daemon-mode MOTD (see caveat)
   -c, --checksum              skip based on checksum, not mod-time & size
@@ -994,9 +1003,9 @@ 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
-@@ -533,6 +534,47 @@ checksum that is generated as the file is transferred, but that
automatic after-the-transfer verification has nothing to do with this
option's before-the-transfer "Does this file need to be updated?" check.
+@@ -588,6 +589,47 @@ 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.
  
 +dit(bf(--db=CONFIG_FILE))  This option specifies a CONFIG_FILE to read
 +that holds connection details for a database of checksum information.
@@ -1045,7 +1054,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
-@@ -270,6 +270,18 @@ is daemon.  This setting has no effect if the "log file" setting is a
+@@ -303,6 +303,18 @@ is daemon.  This setting has no effect if the "log file" setting is a
  non-empty string (either set in the per-modules settings, or inherited
  from the global settings).