patch to do http basic authentication.
[rsync/rsync-patches.git] / jw_rsync3.diff
1 Please CC me.  I'm not subscribed.
2
3 Attached is a patch against 2.5.4pre1 CVS current to add the
4 --link-dest option so rsync will create hardlinks for
5 unchanged regular files to a directory on the destination.
6 This is like --compare-dest except that the result is not a
7 sparse tree.
8
9 Also included is extension to --(ex|in)clude-from to allow -
10 for stdin.
11
12 Could one of the maintainers please add this to the
13 mainline?
14
15 Thanks to Dave Dykstra for feedback on this.
16
17 -- 
18 ________________________________________________________________
19         J.W. Schultz            Pegasystems Technologies
20         email address:          jw@pegasys.ws
21
22                 Remember Cernan and Schmitt
23 ? options-merge.c
24 Index: exclude.c
25 ===================================================================
26 RCS file: /cvsroot/rsync/exclude.c,v
27 retrieving revision 1.42
28 diff -u -r1.42 exclude.c
29 --- exclude.c   18 Feb 2002 19:10:28 -0000      1.42
30 +++ exclude.c   21 Mar 2002 23:31:25 -0000
31 @@ -219,8 +219,14 @@
32                                           int fatal, int include)
33  {
34         struct exclude_struct **list=list1;
35 -       FILE *f = fopen(fname,"r");
36 +       FILE *f;
37         char line[MAXPATHLEN];
38 +
39 +       if (strcmp(fname, "-")) {
40 +               f = fopen(fname,"r");
41 +       } else {
42 +               f = fdopen(0, "r");
43 +       }
44         if (!f) {
45                 if (fatal) {
46                         rsyserr(FERROR, errno,
47 Index: generator.c
48 ===================================================================
49 RCS file: /cvsroot/rsync/generator.c,v
50 retrieving revision 1.37
51 diff -u -r1.37 generator.c
52 --- generator.c 19 Mar 2002 20:16:42 -0000      1.37
53 +++ generator.c 21 Mar 2002 23:31:26 -0000
54 @@ -41,6 +41,7 @@
55  extern int always_checksum;
56  extern int modify_window;
57  extern char *compare_dest;
58 +extern int link_dest;
59  
60  
61  /* choose whether to skip a particular file */
62 @@ -50,6 +51,15 @@
63         if (st->st_size != file->length) {
64                 return 0;
65         }
66 +       if (link_dest) {
67 +               if((st->st_mode & ~_S_IFMT) !=  (file->mode & ~_S_IFMT)) {
68 +                       return 0;
69 +               }
70 +               if (st->st_uid != file->uid || st->st_gid != file->gid) {
71 +                       return 0;
72 +               }
73 +       }
74 +
75         
76         /* if always checksum is set then we use the checksum instead 
77            of the file time to determine whether to sync */
78 @@ -382,6 +392,17 @@
79                         statret = -1;
80                 if (statret == -1)
81                         errno = saveerrno;
82 +#if HAVE_LINK
83 +               else if (link_dest)
84 +               if (do_link(fnamecmpbuf, fname) != 0) {
85 +                       if (verbose > 0)
86 +                               rprintf(FINFO,"link %s => %s : %s\n",
87 +                                       fnamecmpbuf,
88 +                                       fname,
89 +                                       strerror(errno));
90 +                       fnamecmp = fnamecmpbuf;
91 +               }
92 +#endif
93                 else
94                         fnamecmp = fnamecmpbuf;
95         }
96 Index: options.c
97 ===================================================================
98 RCS file: /cvsroot/rsync/options.c,v
99 retrieving revision 1.89
100 diff -u -r1.89 options.c
101 --- options.c   19 Mar 2002 20:16:42 -0000      1.89
102 +++ options.c   21 Mar 2002 23:31:27 -0000
103 @@ -113,6 +113,7 @@
104  char *rsync_path = RSYNC_PATH;
105  char *backup_dir = NULL;
106  int rsync_port = RSYNC_PORT;
107 +int link_dest = 0;
108  
109  int verbose = 0;
110  int quiet = 0;
111 @@ -282,7 +283,7 @@
112        OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS,
113        OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT,
114        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
115 -      OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
116 +      OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, OPT_LINK_DEST,
117        OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
118        OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
119        OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
120 @@ -341,6 +342,7 @@
121    {"timeout",          0,  POPT_ARG_INT,    &io_timeout , 0, 0, 0 },
122    {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir , 0, 0, 0 },
123    {"compare-dest",     0,  POPT_ARG_STRING, &compare_dest , 0, 0, 0 },
124 +  {"link-dest",        0,  POPT_ARG_STRING, 0,               OPT_LINK_DEST, 0, 0 },
125    /* TODO: Should this take an optional int giving the compression level? */
126    {"compress",        'z', POPT_ARG_NONE,   &do_compression , 0, 0, 0 },
127    {"daemon",           0,  POPT_ARG_NONE,   &am_daemon , 0, 0, 0 },
128 @@ -562,6 +564,19 @@
129                         /* popt stores the filename in batch_prefix for us */
130                         read_batch = 1;
131                         break;
132 +               case OPT_LINK_DEST:
133 +#if HAVE_LINK
134 +                       compare_dest = poptGetOptArg(pc);
135 +                       link_dest = 1;
136 +                       break;
137 +#else
138 +                       snprintf(err_buf,sizeof(err_buf),
139 +                                 "hard links are not supported on this %s\n",
140 +                                am_server ? "server" : "client");
141 +                       rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
142 +                       return 0;
143 +#endif
144 +
145  
146                 default:
147                          /* FIXME: If --daemon is specified, then errors for later
148 @@ -785,7 +800,7 @@
149                  *   and it may be an older version that doesn't know this
150                  *   option, so don't send it if client is the sender.
151                  */
152 -               args[ac++] = "--compare-dest";
153 +               args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
154                 args[ac++] = compare_dest;
155         }
156  
157 Index: rsync.yo
158 ===================================================================
159 RCS file: /cvsroot/rsync/rsync.yo,v
160 retrieving revision 1.95
161 diff -u -r1.95 rsync.yo
162 --- rsync.yo    6 Feb 2002 21:20:49 -0000       1.95
163 +++ rsync.yo    21 Mar 2002 23:31:28 -0000
164 @@ -261,6 +261,7 @@
165       --modify-window=NUM     Timestamp window (seconds) for file match (default=0)
166   -T  --temp-dir=DIR          create temporary files in directory DIR
167       --compare-dest=DIR      also compare destination files relative to DIR
168 +     --link-dest=DIR         create hardlinks to DIR for unchanged files
169   -P                          equivalent to --partial --progress
170   -z, --compress              compress file data
171       --exclude=PATTERN       exclude files matching PATTERN
172 @@ -531,6 +532,7 @@
173  option, but instead it adds all exclude patterns listed in the file
174  FILE to the exclude list.  Blank lines in FILE and lines starting with
175  ';' or '#' are ignored.
176 +If \fIFILE\fP is \fB-\fP the list will be read from standard input.
177  
178  dit(bf(--include=PATTERN)) This option tells rsync to not exclude the
179  specified pattern of filenames. This is useful as it allows you to
180 @@ -541,6 +543,7 @@
181  
182  dit(bf(--include-from=FILE)) This specifies a list of include patterns
183  from a file.
184 +If \fIFILE\fP is \fB-\fP the list will be read from standard input.
185  
186  dit(bf(-C, --cvs-exclude)) This is a useful shorthand for excluding a
187  broad range of files that you often don't want to transfer between
188 @@ -595,6 +598,11 @@
189  --partial because partially transferred files will remain in the new
190  temporary destination until they have a chance to be completed.  If DIR is
191  a relative path, it is relative to the destination directory.
192 +
193 +dit(bf(--link-dest=DIR)) This option behaves like \fB--compare-dest\fP but
194 +also will create hard links from \fIDIR\fP to the destination directory for
195 +unchanged files.  Files with changed ownership or permissions will not be
196 +linked.
197  
198  dit(bf(-z, --compress)) With this option, rsync compresses any data from
199  the files that it sends to the destination machine.  This