Updated patches to work with the current trunk.
[rsync/rsync-patches.git] / source-backup.diff
1 This patch adds a --source-backup option that backs up source files
2 removed due to --remove-source-files.
3
4 To 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 diff --git a/options.c b/options.c
13 index e7c6c61..77fb180 100644
14 --- a/options.c
15 +++ b/options.c
16 @@ -33,6 +33,7 @@ extern struct filter_list_struct filter_list;
17  extern struct filter_list_struct daemon_filter_list;
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
24 @@ -712,6 +713,7 @@ void usage(enum logcode F)
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");
32 @@ -966,6 +968,7 @@ static struct poptOption long_options[] = {
33    {"bwlimit",          0,  POPT_ARG_INT,    &bwlimit, 0, 0, 0 },
34    {"no-bwlimit",       0,  POPT_ARG_VAL,    &bwlimit, 0, 0, 0 },
35    {"backup",          'b', POPT_ARG_VAL,    &make_backups, 1, 0, 0 },
36 +  {"source-backup",    0,  POPT_ARG_NONE,   &make_source_backups, 0, 0, 0},
37    {"no-backup",        0,  POPT_ARG_VAL,    &make_backups, 0, 0, 0 },
38    {"backup-dir",       0,  POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
39    {"suffix",           0,  POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
40 @@ -2484,6 +2487,8 @@ void server_options(char **args, int *argc_p)
41                                 goto oom;
42                         args[ac++] = arg;
43                 }
44 +               if (make_source_backups)
45 +                       args[ac++] = "--source-backup";
46         }
47  
48         /* --delete-missing-args needs the cooperation of both sides, but
49 diff --git a/rsync.yo b/rsync.yo
50 index 941f7a5..4080af2 100644
51 --- a/rsync.yo
52 +++ b/rsync.yo
53 @@ -368,6 +368,7 @@ to the detailed description below for a complete description.  verb(
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
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
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,
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.
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
76 diff --git a/sender.c b/sender.c
77 index bf8221d..102540c 100644
78 --- a/sender.c
79 +++ b/sender.c
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;
85  extern int inplace;
86  extern int batch_fd;
87  extern int write_batch;
88 @@ -122,6 +123,7 @@ void successful_send(int ndx)
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;
96 @@ -132,7 +134,11 @@ void successful_send(int ndx)
97                 return;
98         f_name(file, fname);
99  
100 -       if (do_unlink(fname) == 0) {
101 +       if (make_source_backups)
102 +               result = !make_backup(fname, True);
103 +       else
104 +               result = do_unlink(fname);
105 +       if (result == 0) {
106                 if (INFO_GTE(REMOVE, 1))
107                         rprintf(FINFO, "sender removed %s\n", fname);
108         } else