Skip to content

Commit

Permalink
Flush write buffer on an aborted in-place transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne Davison committed Sep 28, 2013
1 parent 60cc5d4 commit 9c7d755
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
17 changes: 11 additions & 6 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Changes since 3.0.9:
- When creating a temp-file, rsync is now a bit smarter about it dot-char
choices, which can fix a problem on OS X with names that start with "..".

- Rsync now sets a cleanup flag for --inplace and --append transfers that
will flush the write buffer if the transfer aborts. This ensures that
more received data gets written out to the disk on an aborted transfer
(which is quite helpful on a slow, flaky connection).

- The reads that map_ptr() now does are aligned on 1K boundaries. This
helps some filesystems and/or files that don't like unaligned reads.

Expand Down Expand Up @@ -158,19 +163,19 @@ Changes since 3.0.9:
how to make this even easier to install & use are welcomed.)

- Improved the speed of some --inplace updates when there are lots of
identical checksum blocks that end up being unsuable.
identical checksum blocks that end up being unusable.

- Added the --outbuf=N|L|B option for chosing the output buffering.
- Added the --outbuf=N|L|B option for choosing the output buffering.

- Repating the --fuzzy option now causes the code to look for fuzzy matches
inside alt-dest directories too.
- Repeating the --fuzzy option now causes the code to look for fuzzy
matches inside alt-dest directories too.

- The --chmod option now supports numeric modes, e.g. --chmod=644,D755

- Added some Solaris xattr code.

- Made an rsync daemon (the listening process) exit with a 0 status when
it was signalled to die. This helps launchd.
it was signaled to die. This helps launchd.

- Improved the RSYNC_* environment variables for the pre-xfer exec script:
when a daemon is sent multiple request args, they are now joined into a
Expand Down Expand Up @@ -211,7 +216,7 @@ Changes since 3.0.9:
- A daemon can now inform a client about a daemon-configured timeout value
so that the client can assist in the keep-alive activity (protocol 31).

- The filter code received some refactoring to make it more extendable, to
- The filter code received some refactoring to make it more extendible, to
read better, and do better sanity checking.

- Really big numbers are now output using our own big-num routine rather
Expand Down
32 changes: 19 additions & 13 deletions cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int cleanup_got_literal = 0;
static const char *cleanup_fname;
static const char *cleanup_new_fname;
static struct file_struct *cleanup_file;
static int cleanup_fd_r, cleanup_fd_w;
static int cleanup_fd_r = -1, cleanup_fd_w = -1;
static pid_t cleanup_pid = 0;

pid_t cleanup_child_pid = -1;
Expand Down Expand Up @@ -155,26 +155,31 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
#include "case_N.h"
switch_step++;

if (cleanup_got_literal && cleanup_fname && cleanup_new_fname
&& keep_partial && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
int tweak_modtime = 0;
if (cleanup_got_literal && (cleanup_fname || cleanup_fd_w != -1)) {
const char *fname = cleanup_fname;
cleanup_fname = NULL;
if (cleanup_fd_r != -1)
if (cleanup_fd_r != -1) {
close(cleanup_fd_r);
cleanup_fd_r = -1;
}
if (cleanup_fd_w != -1) {
flush_write_file(cleanup_fd_w);
close(cleanup_fd_w);
cleanup_fd_w = -1;
}
if (!partial_dir) {
/* We don't want to leave a partial file with a modern time or it
* could be skipped via --update. Setting the time to something
* really old also helps it to stand out as unfinished in an ls. */
tweak_modtime = 1;
cleanup_file->modtime = 0;
if (fname && cleanup_new_fname && keep_partial
&& handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
int tweak_modtime = 0;
if (!partial_dir) {
/* We don't want to leave a partial file with a modern time or it
* could be skipped via --update. Setting the time to something
* really old also helps it to stand out as unfinished in an ls. */
tweak_modtime = 1;
cleanup_file->modtime = 0;
}
finish_transfer(cleanup_new_fname, fname, NULL, NULL,
cleanup_file, tweak_modtime, !partial_dir);
}
finish_transfer(cleanup_new_fname, fname, NULL, NULL,
cleanup_file, tweak_modtime, !partial_dir);
}

/* FALLTHROUGH */
Expand Down Expand Up @@ -266,6 +271,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
void cleanup_disable(void)
{
cleanup_fname = cleanup_new_fname = NULL;
cleanup_fd_r = cleanup_fd_w = -1;
cleanup_got_literal = 0;
}

Expand Down
3 changes: 2 additions & 1 deletion receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ int recv_files(int f_in, int f_out, char *local_name)
if (fd2 == -1) {
rsyserr(FERROR_XFER, errno, "open %s failed",
full_fname(fname));
}
} else if (updating_basis_or_equiv)
cleanup_set(NULL, NULL, file, fd1, fd2);
} else {
fd2 = open_tmpfile(fnametmp, fname, file);
if (fd2 != -1)
Expand Down

0 comments on commit 9c7d755

Please sign in to comment.