File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / rsync / patches / backup-deleted.diff
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:32:36 2021 UTC (4 years ago) by misho
Branches: rsync, MAIN
CVS tags: v3_2_3, HEAD
rsync 3.2.3

    1: This patches adds the --backup-deleted option, as proposed by Jonathan
    2: Kames in bug 7889.
    3: 
    4: To use this patch, run these commands for a successful build:
    5: 
    6:     patch -p1 <patches/backup-deleted.diff
    7:     ./configure                                 (optional if already run)
    8:     make
    9: 
   10: based-on: e94bad1c156fc3910f24e2b3b71a81b0b0bdeb70
   11: diff --git a/generator.c b/generator.c
   12: --- a/generator.c
   13: +++ b/generator.c
   14: @@ -1837,7 +1837,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
   15:  		goto notify_others;
   16:  
   17:  	if (read_batch || whole_file) {
   18: -		if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) {
   19: +		if (inplace && make_backups > 1 && fnamecmp_type == FNAMECMP_FNAME) {
   20:  			if (!(backupptr = get_backup_name(fname)))
   21:  				goto cleanup;
   22:  			if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
   23: @@ -1873,7 +1873,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
   24:  		goto notify_others;
   25:  	}
   26:  
   27: -	if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) {
   28: +	if (inplace && make_backups > 1 && fnamecmp_type == FNAMECMP_FNAME) {
   29:  		if (!(backupptr = get_backup_name(fname))) {
   30:  			close(fd);
   31:  			goto cleanup;
   32: @@ -1997,7 +1997,7 @@ int atomic_create(struct file_struct *file, char *fname, const char *slnk, const
   33:  		skip_atomic = 0;
   34:  
   35:  	if (del_for_flag) {
   36: -		if (make_backups > 0 && !dir_in_the_way) {
   37: +		if (make_backups > 1 && !dir_in_the_way) {
   38:  			if (!make_backup(fname, skip_atomic))
   39:  				return 0;
   40:  		} else if (skip_atomic) {
   41: diff --git a/options.c b/options.c
   42: --- a/options.c
   43: +++ b/options.c
   44: @@ -766,7 +766,8 @@ static struct poptOption long_options[] = {
   45:    {"no-i",             0,  POPT_ARG_VAL,    &itemize_changes, 0, 0, 0 },
   46:    {"bwlimit",          0,  POPT_ARG_STRING, &bwlimit_arg, OPT_BWLIMIT, 0, 0 },
   47:    {"no-bwlimit",       0,  POPT_ARG_VAL,    &bwlimit, 0, 0, 0 },
   48: -  {"backup",          'b', POPT_ARG_VAL,    &make_backups, 1, 0, 0 },
   49: +  {"backup",          'b', POPT_ARG_VAL,    &make_backups, 2, 0, 0 },
   50: +  {"backup-deleted",   0,  POPT_ARG_VAL,    &make_backups, 1, 0, 0 },
   51:    {"no-backup",        0,  POPT_ARG_VAL,    &make_backups, 0, 0, 0 },
   52:    {"backup-dir",       0,  POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
   53:    {"suffix",           0,  POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
   54: @@ -2726,6 +2727,10 @@ void server_options(char **args, int *argc_p)
   55:  	}
   56:  
   57:  	if (am_sender) {
   58: +		/* A remote sender just needs the above -b option.
   59: +		 * A remote receiver will override that with this option. */
   60: +		if (make_backups == 1)
   61: +			args[ac++] = "--backup-deleted";
   62:  		if (max_delete > 0) {
   63:  			if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
   64:  				goto oom;
   65: diff --git a/receiver.c b/receiver.c
   66: --- a/receiver.c
   67: +++ b/receiver.c
   68: @@ -420,7 +420,7 @@ static void handle_delayed_updates(char *local_name)
   69:  		struct file_struct *file = cur_flist->files[ndx];
   70:  		fname = local_name ? local_name : f_name(file, NULL);
   71:  		if ((partialptr = partial_dir_fname(fname)) != NULL) {
   72: -			if (make_backups > 0 && !make_backup(fname, False))
   73: +			if (make_backups > 1 && !make_backup(fname, False))
   74:  				continue;
   75:  			if (DEBUG_GTE(RECV, 1)) {
   76:  				rprintf(FINFO, "renaming %s to %s\n",
   77: @@ -736,7 +736,7 @@ int recv_files(int f_in, int f_out, char *local_name)
   78:  		} else {
   79:  			/* Reminder: --inplace && --partial-dir are never
   80:  			 * enabled at the same time. */
   81: -			if (inplace && make_backups > 0) {
   82: +			if (inplace && make_backups > 1) {
   83:  				if (!(fnamecmp = get_backup_name(fname)))
   84:  					fnamecmp = fname;
   85:  				else
   86: diff --git a/rsync.1.md b/rsync.1.md
   87: --- a/rsync.1.md
   88: +++ b/rsync.1.md
   89: @@ -344,6 +344,7 @@ detailed description below for a complete description.
   90:  --relative, -R           use relative path names
   91:  --no-implied-dirs        don't send implied dirs with --relative
   92:  --backup, -b             make backups (see --suffix & --backup-dir)
   93: +--backup-deleted         make backups only of deleted files
   94:  --backup-dir=DIR         make backups into hierarchy based in DIR
   95:  --suffix=SUFFIX          backup suffix (default ~ w/o --backup-dir)
   96:  --update, -u             skip files that are newer on the receiver
   97: @@ -856,6 +857,13 @@ your home directory (remove the '=' for that).
   98:      trailing inclusion/exclusion of `*`, the auto-added rule would never be
   99:      reached).
  100:  
  101: +0.  --backup-deleted
  102: +
  103: +    With this option, deleted destination files are renamed, while modified
  104: +    destination files are not. Otherwise, this option behaves the same as
  105: +    `--backup`, described above.  Note that if `--backup` is also specified,
  106: +    whichever option is specified last takes precedence.
  107: +
  108:  0.  `--backup-dir=DIR`
  109:  
  110:      This implies the `--backup` option, and tells rsync to store all
  111: diff --git a/rsync.c b/rsync.c
  112: --- a/rsync.c
  113: +++ b/rsync.c
  114: @@ -721,7 +721,7 @@ int finish_transfer(const char *fname, const char *fnametmp,
  115:  		goto do_set_file_attrs;
  116:  	}
  117:  
  118: -	if (make_backups > 0 && overwriting_basis) {
  119: +	if (make_backups > 1 && overwriting_basis) {
  120:  		int ok = make_backup(fname, False);
  121:  		if (!ok)
  122:  			exit_cleanup(RERR_FILEIO);
  123: diff -Nurp a/rsync.1 b/rsync.1
  124: --- a/rsync.1
  125: +++ b/rsync.1
  126: @@ -420,6 +420,7 @@ detailed description below for a complet
  127:  --relative, -R           use relative path names
  128:  --no-implied-dirs        don't send implied dirs with --relative
  129:  --backup, -b             make backups (see --suffix & --backup-dir)
  130: +--backup-deleted         make backups only of deleted files
  131:  --backup-dir=DIR         make backups into hierarchy based in DIR
  132:  --suffix=SUFFIX          backup suffix (default ~ w/o --backup-dir)
  133:  --update, -u             skip files that are newer on the receiver
  134: @@ -931,6 +932,11 @@ your own exclude/protect rule somewhere
  135:  has a high enough priority to be effective (e.g., if your rules specify a
  136:  trailing inclusion/exclusion of \fB*\fP, the auto-added rule would never be
  137:  reached).
  138: +.IP "\-\-backup-deleted"
  139: +With this option, deleted destination files are renamed, while modified
  140: +destination files are not. Otherwise, this option behaves the same as
  141: +\fB\-\-backup\fP, described above.  Note that if \fB\-\-backup\fP is also specified,
  142: +whichever option is specified last takes precedence.
  143:  .IP "\fB\-\-backup-dir=DIR\fP"
  144:  This implies the \fB\-\-backup\fP option, and tells rsync to store all
  145:  backups in the specified directory on the receiving side.  This can be used
  146: diff -Nurp a/rsync.1.html b/rsync.1.html
  147: --- a/rsync.1.html
  148: +++ b/rsync.1.html
  149: @@ -335,6 +335,7 @@ detailed description below for a complet
  150:  --relative, -R           use relative path names
  151:  --no-implied-dirs        don't send implied dirs with --relative
  152:  --backup, -b             make backups (see --suffix &amp; --backup-dir)
  153: +--backup-deleted         make backups only of deleted files
  154:  --backup-dir=DIR         make backups into hierarchy based in DIR
  155:  --suffix=SUFFIX          backup suffix (default ~ w/o --backup-dir)
  156:  --update, -u             skip files that are newer on the receiver
  157: @@ -834,6 +835,13 @@ trailing inclusion/exclusion of <code>*<
  158:  reached).</p>
  159:  </dd>
  160:  
  161: +<dt>-&#8288;-&#8288;backup-deleted</dt><dd>
  162: +<p>With this option, deleted destination files are renamed, while modified
  163: +destination files are not. Otherwise, this option behaves the same as
  164: +<code>--backup</code>, described above.  Note that if <code>--backup</code> is also specified,
  165: +whichever option is specified last takes precedence.</p>
  166: +</dd>
  167: +
  168:  <dt><code>--backup-dir=DIR</code></dt><dd>
  169:  <p>This implies the <code>--backup</code> option, and tells rsync to store all
  170:  backups in the specified directory on the receiving side.  This can be used

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>