Updated patches to work with the current trunk.
[rsync/rsync-patches.git] / source-backup.diff
CommitLineData
92796ae3
WD
1This patch adds a --source-backup option that backs up source files
2removed due to --remove-source-files.
06dba017
WD
3
4To use this patch, run these commands for a successful build:
5
6 patch -p1 <patches/source-backup.diff
7 ./configure (optional if already run)
8 make
9
10-- Matt McCutchen <hashproduct@gmail.com>
11
cc3e685d 12diff --git a/options.c b/options.c
fc557362 13index e7c6c61..77fb180 100644
cc3e685d
WD
14--- a/options.c
15+++ b/options.c
c0c7984e
WD
16@@ -33,6 +33,7 @@ extern struct filter_list_struct filter_list;
17 extern struct filter_list_struct daemon_filter_list;
06dba017
WD
18
19 int make_backups = 0;
20+int make_source_backups = 0;
21
22 /**
23 * If 1, send the whole file as literal data rather than trying to
fc557362 24@@ -712,6 +713,7 @@ void usage(enum logcode F)
06dba017
WD
25 rprintf(F," --existing skip creating new files on receiver\n");
26 rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
27 rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
28+ rprintf(F," --source-backup ... and backs up those files\n");
29 rprintf(F," --del an alias for --delete-during\n");
30 rprintf(F," --delete delete extraneous files from destination dirs\n");
31 rprintf(F," --delete-before receiver deletes before transfer, not during\n");
fc557362 32@@ -966,6 +968,7 @@ static struct poptOption long_options[] = {
06dba017 33 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
6cbbe66d
WD
34 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
35 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
06dba017 36+ {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0},
6cbbe66d 37 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
06dba017
WD
38 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
39 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
fc557362 40@@ -2484,6 +2487,8 @@ void server_options(char **args, int *argc_p)
2ac9130a
WD
41 goto oom;
42 args[ac++] = arg;
43 }
44+ if (make_source_backups)
45+ args[ac++] = "--source-backup";
46 }
06dba017 47
fc557362 48 /* --delete-missing-args needs the cooperation of both sides, but
cc3e685d 49diff --git a/rsync.yo b/rsync.yo
fc557362 50index 941f7a5..4080af2 100644
cc3e685d
WD
51--- a/rsync.yo
52+++ b/rsync.yo
fc557362 53@@ -368,6 +368,7 @@ to the detailed description below for a complete description. verb(
06dba017
WD
54 --existing skip creating new files on receiver
55 --ignore-existing skip updating files that exist on receiver
56 --remove-source-files sender removes synchronized files (non-dir)
57+ --source-backup ... and backs up those files
58 --del an alias for --delete-during
59 --delete delete extraneous files from dest dirs
fc557362
WD
60 --delete-before receiver deletes before xfer, not during
61@@ -1182,6 +1183,14 @@ dit(bf(--remove-source-files)) This tells rsync to remove from the sending
06dba017
WD
62 side the files (meaning non-directories) that are a part of the transfer
63 and have been successfully duplicated on the receiving side.
64
65+dit(bf(--source-backup)) Makes the sender back up the source files it removes
66+due to bf(--remove-source-files). This option is independent of
67+bf(--backup) but uses the same bf(--backup-dir) and bf(--suffix) settings,
f362b23e
WD
68+if any. With bf(--backup-dir), rsync looks for each file's backup dir relative
69+to the source argument the file came from. Consequently, if the
70+bf(--backup-dir) path is relative, each source argument gets a separate backup
71+dir at that path relative to the argument.
06dba017
WD
72+
73 dit(bf(--delete)) This tells rsync to delete extraneous files from the
74 receiving side (ones that aren't on the sending side), but only for the
75 directories that are being synchronized. You must have asked rsync to
cc3e685d 76diff --git a/sender.c b/sender.c
fc557362 77index bf8221d..102540c 100644
cc3e685d
WD
78--- a/sender.c
79+++ b/sender.c
06dba017
WD
80@@ -39,6 +39,7 @@ extern int protocol_version;
81 extern int remove_source_files;
82 extern int updating_basis_file;
83 extern int make_backups;
84+extern int make_source_backups;
06dba017
WD
85 extern int inplace;
86 extern int batch_fd;
fc557362
WD
87 extern int write_batch;
88@@ -122,6 +123,7 @@ void successful_send(int ndx)
06dba017
WD
89 char fname[MAXPATHLEN];
90 struct file_struct *file;
91 struct file_list *flist;
92+ int result;
93
94 if (!remove_source_files)
95 return;
fc557362 96@@ -132,7 +134,11 @@ void successful_send(int ndx)
06dba017
WD
97 return;
98 f_name(file, fname);
99
100- if (do_unlink(fname) == 0) {
101+ if (make_source_backups)
fc557362 102+ result = !make_backup(fname, True);
06dba017
WD
103+ else
104+ result = do_unlink(fname);
105+ if (result == 0) {
fc557362 106 if (INFO_GTE(REMOVE, 1))
06dba017
WD
107 rprintf(FINFO, "sender removed %s\n", fname);
108 } else