1 --- Makefile.in 10 Feb 2004 17:06:11 -0000 1.98
2 +++ Makefile.in 10 Mar 2004 08:00:58 -0000
3 @@ -34,7 +34,7 @@ ZLIBOBJ=zlib/deflate.o zlib/infblock.o z
4 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
5 main.o checksum.o match.o syscall.o log.o backup.o
6 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
7 - fileio.o batch.o clientname.o
8 + fileio.o batch.o clientname.o chmod.o
9 OBJS3=progress.o pipe.o
10 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
11 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
12 --- chmod.c 2004-02-13 17:08:33.000000000 -0800
13 +++ chmod.c 2004-03-09 23:59:27.000000000 -0800
17 +struct chmod_mode_struct {
21 + struct chmod_mode_struct *next;
28 +/* Parse a chmod-style argument, and break it down into one or more AND/OR
29 + * pairs in a linked list.
30 + * We use a state machine to walk through the options - states 1 and 3
31 + * before/including the operation (+, - or =), state 2 after the operation and
32 + * state 4 if we hit an error. */
33 +struct chmod_mode_struct *parse_chmod(char *modestr)
36 + int where = 0, what = 0, op = 0, topbits = 0, topoct = 0, Xkeep = 0;
37 + struct chmod_mode_struct *first_mode = NULL, *curr_mode = NULL,
72 + state = 4; /* Invalid Mode! */
99 + state = 4; /* Invalid Mode! */
108 + if (!*modestr || *modestr == ',') {
109 + prev_mode = curr_mode;
110 + curr_mode = new_array(struct chmod_mode_struct, 1);
112 + prev_mode->next = curr_mode;
114 + first_mode = curr_mode;
115 + curr_mode->next = NULL;
119 + curr_mode->ModeAND = 07777;
120 + curr_mode->ModeOR = (where * what) + topoct;
123 + curr_mode->ModeAND = 07777 - (where * what) - topoct;
124 + curr_mode->ModeOR = 0;
127 + curr_mode->ModeAND = 07777 - (where * 7);
128 + curr_mode->ModeOR = where * what - topoct;
132 + curr_mode->Xkeep = Xkeep;
134 + where = what = topoct = topbits = Xkeep = 0;
139 + free_chmod_mode(first_mode);
146 +/* Takes an existing file permission and a list of AND/OR changes, and
147 + * create a new permissions. */
148 +int tweak_mode(int oldmode, struct chmod_mode_struct *chmod_modes)
150 + int IsX = oldmode & 0111;
151 + int NonPerm = oldmode - (oldmode & 07777);
153 + while (chmod_modes) {
154 + oldmode &= chmod_modes->ModeAND;
155 + if (chmod_modes->Xkeep && !IsX)
156 + oldmode |= chmod_modes->ModeOR & (07777 - 0111);
158 + oldmode |= chmod_modes->ModeOR;
159 + chmod_modes = chmod_modes->next;
162 + return oldmode + NonPerm;
165 +/* Free the linked list created by parse_chmod. */
166 +int free_chmod_mode(struct chmod_mode_struct *chmod_modes)
168 + struct chmod_mode_struct *next;
170 + while (chmod_modes) {
171 + next = chmod_modes->next;
173 + chmod_modes = next;
177 --- flist.c 11 Feb 2004 02:48:58 -0000 1.205
178 +++ flist.c 10 Mar 2004 08:00:59 -0000
179 @@ -33,6 +33,7 @@ extern int verbose;
180 extern int do_progress;
182 extern int am_server;
183 +extern int am_sender;
184 extern int always_checksum;
185 extern int module_id;
186 extern int ignore_errors;
187 @@ -63,6 +64,8 @@ extern int sanitize_paths;
188 extern int read_batch;
189 extern int write_batch;
191 +extern struct chmod_mode_struct *chmod_modes;
193 extern struct exclude_struct **exclude_list;
194 extern struct exclude_struct **server_exclude_list;
195 extern struct exclude_struct **local_exclude_list;
196 @@ -831,7 +834,10 @@ skip_excludes:
198 file->modtime = st.st_mtime;
199 file->length = st.st_size;
200 - file->mode = st.st_mode;
201 + if (chmod_modes && am_sender && S_ISREG(st.st_mode))
202 + file->mode = tweak_mode(st.st_mode, chmod_modes);
204 + file->mode = st.st_mode;
205 file->uid = st.st_uid;
206 file->gid = st.st_gid;
208 --- options.c 22 Feb 2004 08:56:43 -0000 1.139
209 +++ options.c 10 Mar 2004 08:00:59 -0000
210 @@ -119,6 +119,7 @@ char *log_format = NULL;
211 char *password_file = NULL;
212 char *rsync_path = RSYNC_PATH;
213 char *backup_dir = NULL;
214 +char *chmod_mode = NULL;
215 char backup_dir_buf[MAXPATHLEN];
216 int rsync_port = RSYNC_PORT;
218 @@ -132,6 +133,8 @@ int list_only = 0;
219 #define MAX_BATCH_PREFIX_LEN 256 /* Must be less than MAXPATHLEN-13 */
220 char *batch_prefix = NULL;
222 +struct chmod_mode_struct *chmod_modes = NULL;
224 static int daemon_opt; /* sets am_daemon after option error-reporting */
225 static int modify_window_set;
227 @@ -239,6 +242,7 @@ void usage(enum logcode F)
228 rprintf(F," -g, --group preserve group\n");
229 rprintf(F," -D, --devices preserve devices (root only)\n");
230 rprintf(F," -t, --times preserve times\n");
231 + rprintf(F," --chmod=CHMOD change destination permissions\n");
232 rprintf(F," -S, --sparse handle sparse files efficiently\n");
233 rprintf(F," -n, --dry-run show what would have been transferred\n");
234 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
235 @@ -342,6 +346,7 @@ static struct poptOption long_options[]
236 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
237 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
238 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
239 + {"chmod", 0, POPT_ARG_STRING, &chmod_mode, 0, 0, 0 },
240 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
241 {"times", 't', POPT_ARG_NONE, &preserve_times, 0, 0, 0 },
242 {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 },
243 @@ -687,6 +692,13 @@ int parse_arguments(int *argc, const cha
244 exit_cleanup(RERR_SYNTAX);
247 + if (chmod_mode && !(chmod_modes = parse_chmod(chmod_mode))) {
248 + snprintf(err_buf, sizeof err_buf,
249 + "Invalid argument passed to chmod\n");
250 + rprintf(FERROR, "ERROR: %s", err_buf);
254 if (do_progress && !verbose)
257 @@ -932,6 +944,11 @@ void server_options(char **args,int *arg
259 args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
260 args[ac++] = compare_dest;
263 + if (chmod_mode && !am_sender) {
264 + args[ac++] = "--chmod";
265 + args[ac++] = chmod_mode;
268 if (files_from && (!am_sender || remote_filesfrom_file)) {
269 --- proto.h 17 Feb 2004 23:13:06 -0000 1.184
270 +++ proto.h 10 Mar 2004 08:00:59 -0000
271 @@ -25,6 +25,9 @@ void file_checksum(char *fname,char *sum
273 void sum_update(char *p, int len);
274 void sum_end(char *sum);
275 +struct chmod_mode_struct *parse_chmod(char *modestr);
276 +int tweak_mode(int oldmode, struct chmod_mode_struct *chmod_modes);
277 +int free_chmod_mode(struct chmod_mode_struct *chmod_modes);
278 void close_all(void);
279 void _exit_cleanup(int code, const char *file, int line);
280 void cleanup_disable(void);
281 --- rsync.1 2 Feb 2004 18:23:09 -0000 1.163
282 +++ rsync.1 10 Mar 2004 08:01:00 -0000
283 @@ -336,6 +336,7 @@ to the detailed description below for a
284 -g, --group preserve group
285 -D, --devices preserve devices (root only)
286 -t, --times preserve times
287 + --chmod=CHMOD change destination permissions
288 -S, --sparse handle sparse files efficiently
289 -n, --dry-run show what would have been transferred
290 -W, --whole-file copy whole files, no incremental checks
291 @@ -614,6 +615,10 @@ modified cannot be effective; in other w
292 cause the next transfer to behave as if it used -I, and all files will have
293 their checksums compared and show up in log messages even if they haven\&'t
297 +This options tells rsync to apply the listed "chmod" pattern
298 +to the permission of the files on the destination\&.
300 .IP "\fB-n, --dry-run\fP"
301 This tells rsync to not do any file transfers,
302 --- rsync.yo 2 Feb 2004 18:23:09 -0000 1.147
303 +++ rsync.yo 10 Mar 2004 08:01:00 -0000
304 @@ -299,6 +299,7 @@ verb(
305 -g, --group preserve group
306 -D, --devices preserve devices (root only)
307 -t, --times preserve times
308 + --chmod=CHMOD change destination permissions
309 -S, --sparse handle sparse files efficiently
310 -n, --dry-run show what would have been transferred
311 -W, --whole-file copy whole files, no incremental checks
312 @@ -534,6 +535,9 @@ modified cannot be effective; in other w
313 cause the next transfer to behave as if it used -I, and all files will have
314 their checksums compared and show up in log messages even if they haven't
317 +dit(bf(--chmod)) This options tells rsync to apply the listed "chmod" pattern
318 +to the permission of the files on the destination.
320 dit(bf(-n, --dry-run)) This tells rsync to not do any file transfers,
321 instead it will just report the actions it would have taken.
322 --- testsuite/chmod.test 2004-02-13 17:08:33.000000000 -0800
323 +++ testsuite/chmod.test 2004-03-10 00:05:23.000000000 -0800
327 +# Copyright (C) 2002 by Martin Pool <mbp@samba.org>
329 +# This program is distributable under the terms of the GNU GPL (see
332 +# Test that the --chmod option functions correctly.
334 +. $srcdir/testsuite/rsync.fns
340 +fromdir="$scratchdir/from"
341 +todir="$scratchdir/to"
342 +checkdir="$scratchdir/check"
345 +name1="$fromdir/name1"
346 +name2="$fromdir/name2"
347 +echo "This is the file" > "$name1"
348 +echo "This is the other file" > "$name2"
350 +chmod 4700 "$name1" || test_skipped "Can't chown"
352 +# Copy the files we've created over to another directory
353 +checkit "$RSYNC -avv \"$fromdir/\" \"$checkdir/\"" "$fromdir" "$checkdir"
355 +# And then manually make the changes which should occur
356 +chmod ug-s,a+rX $checkdir/*
358 +checkit "$RSYNC -avv --chmod ug-s,a+rX \"$fromdir/\" \"$todir/\"" "$checkdir" "$todir"
360 +# The script would have aborted on error, so getting here means we've won.