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
e20f0bda
WD
9--- orig/flist.c 2005-02-26 19:27:54
10+++ flist.c 2005-02-26 19:34:30
11@@ -59,6 +59,7 @@ extern int copy_unsafe_links;
12 extern int protocol_version;
13 extern int sanitize_paths;
df5a5090 14 extern int orig_umask;
df5a5090 15+extern char *source_cd;
e20f0bda
WD
16
17 extern char curr_dir[MAXPATHLEN];
18
19@@ -1075,13 +1076,14 @@ struct file_list *send_file_list(int f,
df5a5090
WD
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];
a2f30171 39--- orig/options.c 2005-03-01 05:49:24
def2ace9
WD
40+++ options.c 2005-03-01 01:37:22
41@@ -81,6 +81,7 @@ char *filesfrom_host = NULL;
df5a5090
WD
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;
8ab3ce19 49@@ -267,6 +268,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);
8ab3ce19 57@@ -417,6 +419,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 },
8ab3ce19 65@@ -910,6 +913,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");
def2ace9
WD
77@@ -1004,6 +1012,14 @@ int parse_arguments(int *argc, const cha
78 partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
79 if (backup_dir)
df5a5090 80 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
df5a5090
WD
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;
def2ace9 92@@ -1397,6 +1413,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
def2ace9 104--- orig/rsync.yo 2005-03-01 01:22:59
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