From c6b81a9865b49f39f7d388ac64a8d74ce414081e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Sep 1998 06:23:27 +0000 Subject: [PATCH] handle OSes where you can't rename a open file in the cleanup code. --- cleanup.c | 11 ++++++++++- receiver.c | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cleanup.c b/cleanup.c index 05f34527..57fce18f 100644 --- a/cleanup.c +++ b/cleanup.c @@ -27,6 +27,8 @@ int cleanup_got_literal=0; static char *cleanup_fname; static char *cleanup_new_fname; static struct file_struct *cleanup_file; +static int cleanup_fd1, cleanup_fd2; +static struct map_struct *cleanup_buf; void exit_cleanup(int code) { @@ -37,6 +39,9 @@ void exit_cleanup(int code) if (cleanup_got_literal && cleanup_fname && keep_partial) { char *fname = cleanup_fname; cleanup_fname = NULL; + if (cleanup_buf) unmap_file(cleanup_buf); + if (cleanup_fd1 != -1) close(cleanup_fd1); + if (cleanup_fd2 != -1) close(cleanup_fd2); finish_transfer(cleanup_new_fname, fname, cleanup_file); } io_flush(); @@ -55,9 +60,13 @@ void cleanup_disable(void) } -void cleanup_set(char *fnametmp, char *fname, struct file_struct *file) +void cleanup_set(char *fnametmp, char *fname, struct file_struct *file, + struct map_struct *buf, int fd1, int fd2) { cleanup_fname = fnametmp; cleanup_new_fname = fname; cleanup_file = file; + cleanup_buf = buf; + cleanup_fd1 = fd1; + cleanup_fd2 = fd2; } diff --git a/receiver.c b/receiver.c index 03912ade..c565a6f6 100644 --- a/receiver.c +++ b/receiver.c @@ -398,7 +398,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) continue; } - cleanup_set(fnametmp, fname, file); + cleanup_set(fnametmp, fname, file, buf, fd1, fd2); if (!am_server && verbose) rprintf(FINFO,"%s\n",fname); @@ -416,9 +416,9 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) rprintf(FINFO,"renaming %s to %s\n",fnametmp,fname); finish_transfer(fname, fnametmp, file); - + cleanup_disable(); - + if (!recv_ok) { if (csum_length == SUM_LENGTH) { rprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n", -- 2.34.1