Updated to apply cleanly.
[rsync/rsync-patches.git] / source-cd.diff
CommitLineData
df5a5090
WD
1This adds the --source-cd option, which is useful when it is combined with
2the --relative option because it lets you set how much of the source path
3is outside of the transfer. For instance:
4
5rsync -avR --source-cd=/usr local/bin host:/
6
7For two systems where one uses /usr/local/bin and the other /local/bin.
8
dc8e4919 9--- orig/flist.c 2005-02-23 02:57:26
df5a5090
WD
10+++ flist.c 2005-02-22 18:06:57
11@@ -63,6 +63,7 @@ extern int force_delete;
12 extern int orig_umask;
13 extern int make_backups;
14 extern unsigned int curr_dir_len;
15+extern char *source_cd;
16 extern char *log_format;
17 extern char *backup_dir;
18 extern char *backup_suffix;
19@@ -1079,13 +1080,14 @@ struct file_list *send_file_list(int f,
20
21 io_start_buffering_out();
22 if (filesfrom_fd >= 0) {
23- if (argv[0] && !push_dir(argv[0])) {
24- rsyserr(FERROR, errno, "push_dir %s failed",
25- full_fname(argv[0]));
26- exit_cleanup(RERR_FILESELECT);
27- }
28+ source_cd = argv[0];
29 use_ff_fd = 1;
30 }
31+ if (source_cd && !push_dir(source_cd)) {
32+ rsyserr(FERROR, errno, "push_dir %s failed",
33+ full_fname(source_cd));
34+ exit_cleanup(RERR_FILESELECT);
35+ }
36
37 while (1) {
38 char fname2[MAXPATHLEN];
dc8e4919 39--- orig/options.c 2005-02-23 02:57:26
df5a5090
WD
40+++ options.c 2005-02-22 18:06:58
41@@ -80,6 +80,7 @@ char *remote_filesfrom_file = NULL;
42 int eol_nulls = 0;
43 int recurse = 0;
44 int xfer_dirs = 0;
45+char *source_cd = NULL;
46 int am_daemon = 0;
47 int daemon_over_rsh = 0;
48 int do_stats = 0;
dc8e4919 49@@ -266,6 +267,7 @@ void usage(enum logcode F)
df5a5090
WD
50 rprintf(F," -R, --relative use relative path names\n");
51 rprintf(F," --no-relative turn off --relative\n");
52 rprintf(F," --no-implied-dirs don't send implied dirs with -R\n");
53+ rprintf(F," --source-cd=DIR a relative source path starts in this DIR\n");
54 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
55 rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
56 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
dc8e4919 57@@ -416,6 +418,7 @@ static struct poptOption long_options[]
df5a5090
WD
58 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
59 {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 },
60 {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
61+ {"source-cd", 0, POPT_ARG_STRING, &source_cd, 0, 0, 0 },
62 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
63 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
64 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
dc8e4919 65@@ -911,6 +914,11 @@ int parse_arguments(int *argc, const cha
df5a5090
WD
66 batch_name = NULL;
67 }
68 }
69+ if (source_cd && files_from) {
70+ snprintf(err_buf, sizeof err_buf,
71+ "--source-cd cannot be used with --files-from\n");
72+ return 0;
73+ }
74 if (read_batch && files_from) {
75 snprintf(err_buf, sizeof err_buf,
76 "--read-batch cannot be used with --files-from\n");
dc8e4919 77@@ -1007,6 +1015,14 @@ int parse_arguments(int *argc, const cha
df5a5090
WD
78 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
79 if (files_from)
80 files_from = sanitize_path(NULL, files_from, NULL, 0);
81+ if (source_cd)
82+ source_cd = sanitize_path(NULL, source_cd, NULL, 0);
83+ } else if (source_cd && am_daemon) {
84+ int i;
85+ for (i = *argc; i-- > 0; ) {
86+ if ((*argv)[i][0] == '/')
87+ (*argv)[i]++;
88+ }
89 }
90 if (server_filter_list.head && !am_sender) {
91 struct filter_list_struct *elp = &server_filter_list;
dc8e4919 92@@ -1394,6 +1410,11 @@ void server_options(char **args,int *arg
df5a5090
WD
93 } else if (keep_partial)
94 args[ac++] = "--partial";
95
96+ if (source_cd && !am_sender) {
97+ args[ac++] = "--source-cd";
98+ args[ac++] = source_cd;
99+ }
100+
101 if (ignore_errors)
102 args[ac++] = "--ignore-errors";
103
dc8e4919 104--- orig/rsync.yo 2005-02-23 02:57:27
df5a5090
WD
105+++ rsync.yo 2005-02-22 18:20:24
106@@ -304,6 +304,7 @@ to the detailed description below for a
107 -R, --relative use relative path names
108 --no-relative turn off --relative
109 --no-implied-dirs don't send implied dirs with -R
110+ --source-cd=DIR a relative source path starts in this DIR
111 -b, --backup make backups (see --suffix & --backup-dir)
112 --backup-dir=DIR make backups into hierarchy based in DIR
113 --suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
dc8e4919 114@@ -510,6 +511,11 @@ the bf(--no-implied-dirs) option would o
df5a5090
WD
115 which means that if "/path" was a real directory on one machine and a
116 symlink of the other machine, rsync would not try to change this.
117
118+dit(bf(--source-cd=DIR)) Set the specified directory as the default dir for
119+the source side of the transfer. This is most useful when combined with
120+the bf(--relative) option because it lets you move directories from the
121+source path outside the transfer.
122+
123 dit(bf(-b, --backup)) With this option, preexisting destination files are
124 renamed as each file is transferred or deleted. You can control where the
125 backup file goes and what (if any) suffix gets appended using the