extern int io_error;
extern struct stats stats;
+
+/* handling the cleanup when a transfer is interrupted is tricky when
+ --partial is selected. We need to ensure that the partial file is
+ kept if any real data has been transferred */
+static int cleanup_got_literal;
+static char *cleanup_fname;
+static char *cleanup_new_fname;
+static struct file_struct *cleanup_file;
+static void finish_transfer(char *fname, char *fnametmp, struct file_struct *file);
+
+void exit_cleanup(int code)
+{
+ extern int keep_partial;
+
+ signal(SIGUSR1, SIG_IGN);
+
+ if (cleanup_got_literal && cleanup_fname && keep_partial) {
+ char *fname = cleanup_fname;
+ cleanup_fname = NULL;
+ finish_transfer(cleanup_new_fname, fname, cleanup_file);
+ }
+ io_flush();
+ if (cleanup_fname)
+ do_unlink(cleanup_fname);
+ if (code) {
+ kill_all(SIGUSR1);
+ }
+ exit(code);
+}
+
+
/*
free a sums struct
*/
rprintf(FINFO,"data recv %d at %d\n",i,(int)offset);
stats.literal_data += i;
+ cleanup_got_literal = 1;
+
sum_update(data,i);
if (fd != -1 && write_file(fd,data,i) != i) {
}
}
-static char *cleanup_fname;
-
-void exit_cleanup(int code)
-{
- io_flush();
- if (cleanup_fname)
- do_unlink(cleanup_fname);
- signal(SIGUSR1, SIG_IGN);
- if (code) {
- kill_all(SIGUSR1);
- }
- exit(code);
-}
-
void sig_int(void)
{
exit_cleanup(1);
return 1;
}
+/* finish off a file transfer, renaming the file and setting the permissions
+ and ownership */
+static void finish_transfer(char *fname, char *fnametmp, struct file_struct *file)
+{
+ if (make_backups) {
+ char fnamebak[MAXPATHLEN];
+ if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
+ rprintf(FERROR,"backup filename too long\n");
+ return;
+ }
+ slprintf(fnamebak,sizeof(fnamebak)-1,"%s%s",fname,backup_suffix);
+ if (do_rename(fname,fnamebak) != 0 && errno != ENOENT) {
+ rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
+ return;
+ }
+ }
+
+ /* move tmp file over real file */
+ if (do_rename(fnametmp,fname) != 0) {
+ if (errno == EXDEV) {
+ /* rename failed on cross-filesystem link.
+ Copy the file instead. */
+ if (copy_file(fnametmp,fname, file->mode)) {
+ rprintf(FERROR,"copy %s -> %s : %s\n",
+ fnametmp,fname,strerror(errno));
+ } else {
+ set_perms(fname,file,NULL,0);
+ }
+ do_unlink(fnametmp);
+ } else {
+ rprintf(FERROR,"rename %s -> %s : %s\n",
+ fnametmp,fname,strerror(errno));
+ do_unlink(fnametmp);
+ }
+ } else {
+ set_perms(fname,file,NULL,0);
+ }
+}
+
+
int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
{
int fd1,fd2;
}
while (1) {
+ cleanup_fname = NULL;
+ cleanup_got_literal = 0;
+
i = read_int(f_in);
if (i == -1) {
if (phase==0 && remote_version >= 13) {
}
cleanup_fname = fnametmp;
+ cleanup_new_fname = fname;
+ cleanup_file = file;
if (!am_server && verbose)
printf("%s\n",fname);
if (verbose > 2)
rprintf(FINFO,"renaming %s to %s\n",fnametmp,fname);
-
- if (make_backups) {
- char fnamebak[MAXPATHLEN];
- if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
- rprintf(FERROR,"backup filename too long\n");
- continue;
- }
- slprintf(fnamebak,sizeof(fnamebak)-1,"%s%s",fname,backup_suffix);
- if (do_rename(fname,fnamebak) != 0 && errno != ENOENT) {
- rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
- continue;
- }
- }
-
- /* move tmp file over real file */
- if (do_rename(fnametmp,fname) != 0) {
- if (errno == EXDEV) {
- /* rename failed on cross-filesystem link.
- Copy the file instead. */
- if (copy_file(fnametmp,fname, file->mode)) {
- rprintf(FERROR,"copy %s -> %s : %s\n",
- fnametmp,fname,strerror(errno));
- } else {
- set_perms(fname,file,NULL,0);
- }
- do_unlink(fnametmp);
- } else {
- rprintf(FERROR,"rename %s -> %s : %s\n",
- fnametmp,fname,strerror(errno));
- do_unlink(fnametmp);
- }
- } else {
- set_perms(fname,file,NULL,0);
- }
+ finish_transfer(fname, fnametmp, file);
+
cleanup_fname = NULL;
-
if (!recv_ok) {
if (csum_length == SUM_LENGTH) {