Added a TODO comment.
[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
12--- old/options.c
13+++ new/options.c
14@@ -29,6 +29,7 @@ extern struct filter_list_struct filter_
15 extern struct filter_list_struct server_filter_list;
16
17 int make_backups = 0;
18+int make_source_backups = 0;
19
20 /**
21 * If 1, send the whole file as literal data rather than trying to
6cbbe66d 22@@ -351,6 +352,7 @@ void usage(enum logcode F)
06dba017
WD
23 rprintf(F," --existing skip creating new files on receiver\n");
24 rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
25 rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
26+ rprintf(F," --source-backup ... and backs up those files\n");
27 rprintf(F," --del an alias for --delete-during\n");
28 rprintf(F," --delete delete extraneous files from destination dirs\n");
29 rprintf(F," --delete-before receiver deletes before transfer, not during\n");
6cbbe66d 30@@ -570,6 +572,7 @@ static struct poptOption long_options[]
06dba017 31 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
6cbbe66d
WD
32 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
33 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
06dba017 34+ {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0},
6cbbe66d 35 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
06dba017
WD
36 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
37 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
6cbbe66d 38@@ -1836,7 +1839,8 @@ void server_options(char **args,int *arg
06dba017
WD
39 args[ac++] = "--super";
40 if (size_only)
41 args[ac++] = "--size-only";
42- }
43+ } else if (make_source_backups)
44+ args[ac++] = "--source-backup";
45
46 if (modify_window_set) {
47 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
48--- old/rsync.yo
49+++ new/rsync.yo
6cbbe66d 50@@ -350,6 +350,7 @@ to the detailed description below for a
06dba017
WD
51 --existing skip creating new files on receiver
52 --ignore-existing skip updating files that exist on receiver
53 --remove-source-files sender removes synchronized files (non-dir)
54+ --source-backup ... and backs up those files
55 --del an alias for --delete-during
56 --delete delete extraneous files from dest dirs
57 --delete-before receiver deletes before transfer (default)
6cbbe66d 58@@ -1004,6 +1005,15 @@ dit(bf(--remove-source-files)) This tell
06dba017
WD
59 side the files (meaning non-directories) that are a part of the transfer
60 and have been successfully duplicated on the receiving side.
61
62+dit(bf(--source-backup)) Makes the sender back up the source files it removes
63+due to bf(--remove-source-files). This option is independent of
64+bf(--backup) but uses the same bf(--backup-dir) and bf(--suffix) settings,
65+if any. With bf(--backup-dir), each backup file is placed inside the backup
66+dir according to the source file's full path from the working directory
92796ae3 67+(backup-dir + source argument path + file-list path); if you want files placed according
06dba017
WD
68+to the file-list path, you could either make appropriate symlinks or have the
69+sender "cd" into the source directory so that the source argument is just ".".
70+
71 dit(bf(--delete)) This tells rsync to delete extraneous files from the
72 receiving side (ones that aren't on the sending side), but only for the
73 directories that are being synchronized. You must have asked rsync to
74--- old/sender.c
75+++ new/sender.c
76@@ -39,6 +39,7 @@ extern int protocol_version;
77 extern int remove_source_files;
78 extern int updating_basis_file;
79 extern int make_backups;
80+extern int make_source_backups;
81 extern int do_progress;
82 extern int inplace;
83 extern int batch_fd;
84@@ -123,6 +124,7 @@ void successful_send(int ndx)
85 char fname[MAXPATHLEN];
86 struct file_struct *file;
87 struct file_list *flist;
88+ int result;
89
90 if (!remove_source_files)
91 return;
92@@ -139,7 +141,11 @@ void successful_send(int ndx)
93 return;
94 f_name(file, fname);
95
96- if (do_unlink(fname) == 0) {
97+ if (make_source_backups)
98+ result = !make_backup(fname);
99+ else
100+ result = do_unlink(fname);
101+ if (result == 0) {
102 if (verbose > 1)
103 rprintf(FINFO, "sender removed %s\n", fname);
104 } else