aboutsummaryrefslogtreecommitdiffstats
path: root/cleanup.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2013-09-28 10:11:35 -0700
committerWayne Davison <wayned@samba.org>2013-09-28 10:40:27 -0700
commit9c7d755dfe9ebfe7f7c53b63c047bae267de7272 (patch)
tree07ef680710939bfb2e963c5a6d38407f08266ec5 /cleanup.c
parent60cc5d4b7837644884b6721ea4d55a0c8f933694 (diff)
downloadandroid_external_rsync-9c7d755dfe9ebfe7f7c53b63c047bae267de7272.tar.gz
android_external_rsync-9c7d755dfe9ebfe7f7c53b63c047bae267de7272.tar.bz2
android_external_rsync-9c7d755dfe9ebfe7f7c53b63c047bae267de7272.zip
Flush write buffer on an aborted in-place transfer.
Diffstat (limited to 'cleanup.c')
-rw-r--r--cleanup.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/cleanup.c b/cleanup.c
index d84abb5d..c750ba65 100644
--- a/cleanup.c
+++ b/cleanup.c
@@ -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;
@@ -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 */
@@ -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;
}