Simplified the code that avoids the re-stat for already-existing dirs.
[rsync/rsync-patches.git] / keep-dirlinks.diff
CommitLineData
92bf9171 1--- generator.c 18 May 2004 08:50:17 -0000 1.85
d1497129 2+++ generator.c 5 Jun 2004 16:08:33 -0000
92bf9171
WD
3@@ -26,6 +26,7 @@
4 extern int verbose;
5 extern int dry_run;
6 extern int relative_paths;
7+extern int keep_dirlinks;
8 extern int preserve_links;
9 extern int am_root;
10 extern int preserve_devices;
5e549c8f
WD
11@@ -302,6 +303,15 @@ void recv_generator(char *fname, struct
12 return;
13 }
92bf9171 14
5e549c8f
WD
15+#if SUPPORT_LINKS
16+ if (statret == 0 && keep_dirlinks
17+ && S_ISLNK(st.st_mode) && S_ISDIR(file->mode)) {
18+ STRUCT_STAT st2;
19+ if (do_stat(fname, &st2) == 0 && S_ISDIR(st2.st_mode))
20+ st = st2;
21+ }
22+#endif
23+
24 if (statret == 0 &&
25 !preserve_perms &&
26 (S_ISDIR(st.st_mode) == S_ISDIR(file->mode))) {
d1497129
WD
27@@ -338,9 +348,10 @@ void recv_generator(char *fname, struct
28 full_fname(fname));
e748400b 29 }
e748400b
WD
30 }
31- /* f_out is set to -1 when doing final directory
32- permission and modification time repair */
33- if (set_perms(fname,file,NULL,0) && verbose && (f_out != -1))
34+ /* f_out is set to -1 when doing final directory-permission
35+ * and modification-time repair. */
d1497129
WD
36+ if (set_perms(fname, file, statret ? NULL : &st, 0)
37+ && verbose && f_out != -1)
e748400b
WD
38 rprintf(FINFO,"%s/\n",fname);
39 return;
40 }
92bf9171 41--- options.c 27 May 2004 21:51:53 -0000 1.153
d1497129 42+++ options.c 5 Jun 2004 16:08:34 -0000
92bf9171
WD
43@@ -38,6 +38,7 @@ int make_backups = 0;
44 int whole_file = -1;
45
46 int archive_mode = 0;
47+int keep_dirlinks = 0;
48 int copy_links = 0;
49 int preserve_links = 0;
50 int preserve_hard_links = 0;
5e549c8f
WD
51@@ -232,6 +233,7 @@ void usage(enum logcode F)
52 rprintf(F," --backup-dir make backups into this directory\n");
92bf9171
WD
53 rprintf(F," --suffix=SUFFIX backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
54 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
92bf9171 55+ rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
5e549c8f 56 rprintf(F," -l, --links copy symlinks as symlinks\n");
92bf9171
WD
57 rprintf(F," -L, --copy-links copy the referent of all symlinks\n");
58 rprintf(F," --copy-unsafe-links copy the referent of \"unsafe\" symlinks\n");
92bf9171
WD
59@@ -338,6 +340,7 @@ static struct poptOption long_options[]
60 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
61 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
62 {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
63+ {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
64 {"links", 'l', POPT_ARG_NONE, &preserve_links, 0, 0, 0 },
65 {"copy-links", 'L', POPT_ARG_NONE, &copy_links, 0, 0, 0 },
66 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
67@@ -818,6 +821,8 @@ void server_options(char **args,int *arg
68 argstr[x++] = 'l';
69 if (copy_links)
70 argstr[x++] = 'L';
71+ if (keep_dirlinks && am_sender)
72+ argstr[x++] = 'K';
73
74 if (whole_file > 0)
75 argstr[x++] = 'W';
76--- rsync.yo 21 May 2004 09:44:32 -0000 1.170
d1497129 77+++ rsync.yo 5 Jun 2004 16:08:35 -0000
92bf9171
WD
78@@ -289,6 +289,7 @@ verb(
79 --backup-dir make backups into this directory
80 --suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
81 -u, --update update only (don't overwrite newer files)
82+ -K, --keep-dirlinks treat symlinked dir on receiver as dir
83 -l, --links copy symlinks as symlinks
84 -L, --copy-links copy the referent of all symlinks
85 --copy-unsafe-links copy the referent of "unsafe" symlinks
86@@ -479,6 +480,10 @@ symlink where the destination has a file
87 regardless of the timestamps. This might change in the future (feel
88 free to comment on this on the mailing list if you have an opinion).
89
90+dit(bf(-K, --keep-dirlinks)) On the receiving side, if a symlink is
91+pointing to a directory, it will be treated as matching a directory
92+from the sender.
93+
94 dit(bf(-l, --links)) When symlinks are encountered, recreate the
95 symlink on the destination.
96