1 Delay the renaming of all the temp files until the end of the transfer.
3 --- options.c 1 Jan 2005 21:08:14 -0000 1.193
4 +++ options.c 10 Jan 2005 10:16:54 -0000
5 @@ -97,6 +97,7 @@ int modify_window = 0;
9 +int delay_renames = 0;
10 long block_size = 0; /* "long" because popt can't set an int32. */
13 @@ -278,6 +279,7 @@ void usage(enum logcode F)
14 rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
15 rprintf(F," --partial keep partially transferred files\n");
16 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
17 + rprintf(F," --delay-renames renames transferred files into place at end\n");
18 rprintf(F," --force force deletion of directories even if not empty\n");
19 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
20 rprintf(F," --timeout=TIME set I/O timeout in seconds\n");
21 @@ -390,6 +392,7 @@ static struct poptOption long_options[]
22 {"progress", 0, POPT_ARG_NONE, &do_progress, 0, 0, 0 },
23 {"partial", 0, POPT_ARG_NONE, &keep_partial, 0, 0, 0 },
24 {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
25 + {"delay-renames", 0, POPT_ARG_NONE, &delay_renames, 0, 0, 0 },
26 {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 },
27 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
28 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
29 @@ -944,11 +947,15 @@ int parse_arguments(int *argc, const cha
30 bwlimit_writemax = 512;
33 + if (delay_renames && !partial_dir)
34 + partial_dir = ".~tmp~";
39 snprintf(err_buf, sizeof err_buf,
40 - "--inplace cannot be used with --partial-dir\n");
41 + "--inplace cannot be used with --%s\n",
42 + delay_renames ? "delay-renames" : "partial-dir");
46 @@ -1185,6 +1192,8 @@ void server_options(char **args,int *arg
47 if (partial_dir && am_sender) {
48 args[ac++] = "--partial-dir";
49 args[ac++] = partial_dir;
51 + args[ac++] = "--delay-renames";
52 } else if (keep_partial)
53 args[ac++] = "--partial";
55 --- receiver.c 10 Jan 2005 10:03:10 -0000 1.113
56 +++ receiver.c 10 Jan 2005 10:16:54 -0000
57 @@ -52,6 +52,7 @@ extern int orig_umask;
58 extern int keep_partial;
59 extern int checksum_seed;
61 +extern int delay_renames;
63 extern struct exclude_list_struct server_exclude_list;
65 @@ -344,6 +345,7 @@ int recv_files(int f_in, struct file_lis
66 char fnametmp[MAXPATHLEN];
67 char *fnamecmp, *partialptr;
68 char fnamecmpbuf[MAXPATHLEN];
69 + uchar *delayed_bits = NULL;
70 struct file_struct *file;
71 struct stats initial_stats;
72 int save_make_backups = make_backups;
73 @@ -357,6 +359,12 @@ int recv_files(int f_in, struct file_lis
74 flist->hlink_pool = NULL;
77 + if (delay_renames) {
78 + if (!(delayed_bits = new_array(char, (flist->count + 7) / 8)))
79 + out_of_memory("recv_files");
80 + memset(delayed_bits, 0, (flist->count + 7) / 8);
86 @@ -566,7 +574,7 @@ int recv_files(int f_in, struct file_lis
87 exit_cleanup(RERR_FILEIO);
90 - if (recv_ok || inplace) {
91 + if ((recv_ok && !delay_renames) || inplace) {
92 finish_transfer(fname, fnametmp, file, recv_ok, 1);
93 if (partialptr != fname && fnamecmp == partialptr) {
94 do_unlink(partialptr);
95 @@ -576,6 +584,8 @@ int recv_files(int f_in, struct file_lis
96 && handle_partial_dir(partialptr, PDIR_CREATE)) {
97 finish_transfer(partialptr, fnametmp, file, recv_ok,
99 + if (delay_renames && recv_ok)
100 + delayed_bits[i/8] |= 1 << (i % 8);
104 @@ -615,6 +625,33 @@ int recv_files(int f_in, struct file_lis
106 make_backups = save_make_backups;
108 + if (delay_renames) {
109 + for (i = 0; i < flist->count; i++) {
110 + struct file_struct *file = flist->files[i];
111 + if (!file->basename
112 + || !(delayed_bits[i/8] & (1 << (i % 8))))
114 + fname = local_name ? local_name : f_name(file);
115 + partialptr = partial_dir_fname(fname);
117 + if (make_backups && !make_backup(fname))
120 + rprintf(FINFO, "renaming %s to %s\n",
121 + partialptr, fname);
123 + if (do_rename(partialptr, fname) < 0) {
124 + rsyserr(FERROR, errno,
125 + "rename failed for %s (from %s)",
126 + fname, partialptr);
128 + handle_partial_dir(partialptr,
135 if (delete_after && recurse && !local_name && flist->count > 0)
138 --- rsync.yo 8 Dec 2004 17:30:40 -0000 1.205
139 +++ rsync.yo 10 Jan 2005 10:16:56 -0000
140 @@ -348,6 +348,7 @@ verb(
141 --max-size=SIZE don't transfer any file larger than SIZE
142 --partial keep partially transferred files
143 --partial-dir=DIR put a partially transferred file into DIR
144 + --delay-renames renames transferred files into place at end
145 --force force deletion of dirs even if not empty
146 --numeric-ids don't map uid/gid values by user/group name
147 --timeout=TIME set I/O timeout in seconds
148 @@ -544,9 +545,10 @@ or appended data, and also on systems th
151 The option implies --partial (since an interrupted transfer does not delete
152 -the file), but conflicts with --partial-dir, --compare-dest, --copy-dest, and
153 ---link-dest (a future rsync version will hopefully update the protocol to
154 -remove some of these restrictions).
155 +the file), but conflicts with --partial-dir, --compare-dest, --copy-dest,
156 +--link-dest, and --delay-renames.
157 +(A future rsync version will hopefully update the protocol to
158 +remove some of these restrictions.)
160 WARNING: The file's data will be in an inconsistent state during the
161 transfer (and possibly afterward if the transfer gets interrupted), so you
162 @@ -967,6 +969,17 @@ environment and then just use the -P opt
163 does not look for this environment value is when --inplace was also
164 specified (since --inplace conflicts with --partial-dir).
166 +dit(bf(--delay-renames)) This option puts the temporary file from each
167 +updated file into the file's partial-dir (see above) until the end of the
168 +transfer, at which time all the files are renamed into place in rapid
169 +succession. This attempts to make the updating of the files a little more
170 +atomic. If you don't specify the --partial-dir option, this option will
171 +cause it to default to ".~tmp~" (RSYNC_PARTIAL_DIR is not consulted for
172 +this value). Conflicts with --inplace.
174 +See also the "atomic-rsync" perl script in the "support" subdir for an
175 +update algorithm that is even more atomic (it uses --link-dest).
177 dit(bf(--progress)) This option tells rsync to print information
178 showing the progress of the transfer. This gives a bored user