Commit | Line | Data |
---|---|---|
372bd02a WD |
1 | Delay the renaming of all the temp files until the end of the transfer. |
2 | ||
d37913ac | 3 | --- orig/options.c 2005-01-25 03:26:51 |
3519f785 | 4 | +++ options.c 2005-01-25 09:21:08 |
b76d92e6 | 5 | @@ -101,6 +101,7 @@ int modify_window = 0; |
372bd02a WD |
6 | int blocking_io = -1; |
7 | int checksum_seed = 0; | |
8 | int inplace = 0; | |
9 | +int delay_renames = 0; | |
10 | long block_size = 0; /* "long" because popt can't set an int32. */ | |
11 | ||
12 | ||
d37913ac WD |
13 | @@ -288,6 +289,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"); | |
3519f785 | 17 | + rprintf(F," --delay-renames rename all transferred files into place at end\n"); |
d37913ac WD |
18 | rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n"); |
19 | rprintf(F," --timeout=TIME set I/O timeout in seconds\n"); | |
20 | rprintf(F," -I, --ignore-times turn off mod time & file size quick check\n"); | |
21 | @@ -407,6 +409,7 @@ static struct poptOption long_options[] | |
372bd02a WD |
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 }, | |
d37913ac | 29 | @@ -995,11 +998,15 @@ int parse_arguments(int *argc, const cha |
372bd02a WD |
30 | bwlimit_writemax = 512; |
31 | } | |
32 | ||
33 | + if (delay_renames && !partial_dir) | |
34 | + partial_dir = ".~tmp~"; | |
35 | + | |
36 | if (inplace) { | |
37 | #if HAVE_FTRUNCATE | |
3519f785 | 38 | if (partial_dir) { |
372bd02a WD |
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"); | |
43 | return 0; | |
44 | } | |
45 | keep_partial = 0; | |
d37913ac | 46 | @@ -1236,6 +1243,8 @@ void server_options(char **args,int *arg |
372bd02a WD |
47 | if (partial_dir && am_sender) { |
48 | args[ac++] = "--partial-dir"; | |
49 | args[ac++] = partial_dir; | |
50 | + if (delay_renames) | |
51 | + args[ac++] = "--delay-renames"; | |
52 | } else if (keep_partial) | |
53 | args[ac++] = "--partial"; | |
54 | ||
b76d92e6 | 55 | --- orig/receiver.c 2005-01-24 01:43:10 |
0f626034 | 56 | +++ receiver.c 2005-01-10 10:16:54 |
b76d92e6 | 57 | @@ -48,6 +48,7 @@ extern int orig_umask; |
372bd02a WD |
58 | extern int keep_partial; |
59 | extern int checksum_seed; | |
60 | extern int inplace; | |
61 | +extern int delay_renames; | |
62 | ||
4f9b6a01 | 63 | extern struct filter_list_struct server_filter_list; |
372bd02a | 64 | |
b76d92e6 | 65 | @@ -272,6 +273,7 @@ int recv_files(int f_in, struct file_lis |
372bd02a WD |
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; | |
3519f785 | 73 | @@ -285,6 +287,13 @@ int recv_files(int f_in, struct file_lis |
372bd02a WD |
74 | flist->hlink_pool = NULL; |
75 | } | |
76 | ||
77 | + if (delay_renames) { | |
3519f785 WD |
78 | + int sz = (flist->count + 7) / 8; |
79 | + if (!(delayed_bits = new_array(char, sz))) | |
372bd02a | 80 | + out_of_memory("recv_files"); |
3519f785 | 81 | + memset(delayed_bits, 0, sz); |
372bd02a WD |
82 | + } |
83 | + | |
84 | while (1) { | |
85 | cleanup_disable(); | |
86 | ||
3519f785 | 87 | @@ -499,7 +508,7 @@ int recv_files(int f_in, struct file_lis |
372bd02a WD |
88 | exit_cleanup(RERR_FILEIO); |
89 | } | |
90 | ||
91 | - if (recv_ok || inplace) { | |
92 | + if ((recv_ok && !delay_renames) || inplace) { | |
93 | finish_transfer(fname, fnametmp, file, recv_ok, 1); | |
94 | if (partialptr != fname && fnamecmp == partialptr) { | |
95 | do_unlink(partialptr); | |
3519f785 | 96 | @@ -509,6 +518,8 @@ int recv_files(int f_in, struct file_lis |
372bd02a WD |
97 | && handle_partial_dir(partialptr, PDIR_CREATE)) { |
98 | finish_transfer(partialptr, fnametmp, file, recv_ok, | |
99 | !partial_dir); | |
100 | + if (delay_renames && recv_ok) | |
101 | + delayed_bits[i/8] |= 1 << (i % 8); | |
102 | } else { | |
103 | partialptr = NULL; | |
104 | do_unlink(fnametmp); | |
3519f785 | 105 | @@ -548,6 +559,33 @@ int recv_files(int f_in, struct file_lis |
372bd02a WD |
106 | } |
107 | make_backups = save_make_backups; | |
108 | ||
109 | + if (delay_renames) { | |
110 | + for (i = 0; i < flist->count; i++) { | |
111 | + struct file_struct *file = flist->files[i]; | |
112 | + if (!file->basename | |
113 | + || !(delayed_bits[i/8] & (1 << (i % 8)))) | |
114 | + continue; | |
115 | + fname = local_name ? local_name : f_name(file); | |
116 | + partialptr = partial_dir_fname(fname); | |
117 | + if (partialptr) { | |
118 | + if (make_backups && !make_backup(fname)) | |
119 | + continue; | |
120 | + if (verbose > 2) { | |
121 | + rprintf(FINFO, "renaming %s to %s\n", | |
122 | + partialptr, fname); | |
123 | + } | |
124 | + if (do_rename(partialptr, fname) < 0) { | |
125 | + rsyserr(FERROR, errno, | |
126 | + "rename failed for %s (from %s)", | |
127 | + fname, partialptr); | |
128 | + } else { | |
129 | + handle_partial_dir(partialptr, | |
130 | + PDIR_DELETE); | |
131 | + } | |
132 | + } | |
133 | + } | |
134 | + } | |
135 | + | |
136 | if (delete_after && recurse && !local_name && flist->count > 0) | |
137 | delete_files(flist); | |
138 | ||
d37913ac | 139 | --- orig/rsync.yo 2005-01-25 03:26:51 |
3519f785 | 140 | +++ rsync.yo 2005-01-25 09:30:44 |
d37913ac WD |
141 | @@ -353,6 +353,7 @@ verb( |
142 | --max-size=SIZE don't transfer any file larger than SIZE | |
143 | --partial keep partially transferred files | |
144 | --partial-dir=DIR put a partially transferred file into DIR | |
3519f785 | 145 | + --delay-renames rename transferred files into place at end |
d37913ac WD |
146 | --numeric-ids don't map uid/gid values by user/group name |
147 | --timeout=TIME set I/O timeout in seconds | |
148 | -I, --ignore-times turn off mod time & file size quick check | |
149 | @@ -549,9 +550,9 @@ or appended data, and also on systems th | |
372bd02a WD |
150 | bound. |
151 | ||
152 | The option implies --partial (since an interrupted transfer does not delete | |
0f626034 WD |
153 | -the file), but conflicts with --partial-dir. Prior to rsync 2.6.4 |
154 | ---inplace was also incompatible with --compare-dest, --copy-dest, and | |
155 | ---link-dest. | |
156 | +the file), but conflicts with --partial-dir and --delay-renames. | |
157 | +Prior to rsync 2.6.4 --inplace was also incompatible with --compare-dest, | |
158 | +--copy-dest, and --link-dest. | |
372bd02a WD |
159 | |
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 | |
3519f785 | 162 | @@ -1028,13 +1029,26 @@ is a security risk. E.g. AVOID "/tmp". |
372bd02a | 163 | |
3519f785 WD |
164 | You can also set the partial-dir value the RSYNC_PARTIAL_DIR environment |
165 | variable. Setting this in the environment does not force --partial to be | |
166 | -enabled, but rather it effects where partial files go when --partial (or | |
167 | --P) is used. For instance, instead of specifying --partial-dir=.rsync-tmp | |
168 | +enabled, but rather it effects where partial files go when --partial is | |
169 | +specified. For instance, instead of using --partial-dir=.rsync-tmp | |
170 | along with --progress, you could set RSYNC_PARTIAL_DIR=.rsync-tmp in your | |
171 | environment and then just use the -P option to turn on the use of the | |
172 | -.rsync-tmp dir for partial transfers. The only time the --partial option | |
173 | -does not look for this environment value is when --inplace was also | |
174 | -specified (since --inplace conflicts with --partial-dir). | |
175 | +.rsync-tmp dir for partial transfers. The only times the --partial option | |
176 | +does not look for this environment value is (1) when --inplace was also | |
177 | +specified (since --inplace conflicts with --partial-dir), and (2) when | |
178 | +--delay-renames was also specified (see below). | |
179 | + | |
372bd02a WD |
180 | +dit(bf(--delay-renames)) This option puts the temporary file from each |
181 | +updated file into the file's partial-dir (see above) until the end of the | |
182 | +transfer, at which time all the files are renamed into place in rapid | |
183 | +succession. This attempts to make the updating of the files a little more | |
184 | +atomic. If you don't specify the --partial-dir option, this option will | |
185 | +cause it to default to ".~tmp~" (RSYNC_PARTIAL_DIR is not consulted for | |
186 | +this value). Conflicts with --inplace. | |
187 | + | |
188 | +See also the "atomic-rsync" perl script in the "support" subdir for an | |
3519f785 WD |
189 | +update algorithm that is even more atomic (it uses --link-dest and a |
190 | +parallel hierarchy of files). | |
191 | ||
372bd02a WD |
192 | dit(bf(--progress)) This option tells rsync to print information |
193 | showing the progress of the transfer. This gives a bored user |