From 904e4022a4c23c04d3914432b05561096b0f6d0c Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Wed, 26 Mar 2003 09:59:37 +0000 Subject: [PATCH] * file.c (copy_file_file): Fix data corruption if mc_write() does not write n_read bytes at once. (move_file_file): Eliminate retry_src_lstat label. --- src/ChangeLog | 6 ++++++ src/file.c | 19 +++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8a7dd978e..68f722d3d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-03-26 Andrew V. Samoilov + + * file.c (copy_file_file): Fix data corruption if mc_write() + does not write n_read bytes at once. + (move_file_file): Eliminate retry_src_lstat label. + 2003-03-24 Andrew V. Samoilov * view.c (get_line_at): Set prev properly for reverse search. diff --git a/src/file.c b/src/file.c index 4f4f8cb7e..7c37e2ebb 100644 --- a/src/file.c +++ b/src/file.c @@ -715,6 +715,7 @@ copy_file_file (FileOpContext *ctx, char *src_path, char *dst_path, gettimeofday (&tv_current, NULL); if (n_read > 0) { + char *t = buf; n_read_total += n_read; /* Windows NT ftp servers report that files have no @@ -729,18 +730,18 @@ copy_file_file (FileOpContext *ctx, char *src_path, char *dst_path, /* dst_write */ while ((n_written = - mc_write (dest_desc, buf, n_read)) < n_read) { + mc_write (dest_desc, t, n_read)) < n_read) { if (n_written > 0) { n_read -= n_written; + t += n_written; continue; } return_status = file_error (_ (" Cannot write target file \"%s\" \n %s "), dst_path); - if (return_status == FILE_RETRY) - continue; - goto ret; + if (return_status != FILE_RETRY) + goto ret; } } @@ -1119,14 +1120,12 @@ move_file_file (FileOpContext *ctx, char *s, char *d, mc_refresh (); - retry_src_lstat: - if (mc_lstat (s, &src_stats) != 0) { + while (mc_lstat (s, &src_stats) != 0) { /* Source doesn't exist */ return_status = file_error (_(" Cannot stat file \"%s\" \n %s "), s); - if (return_status == FILE_RETRY) - goto retry_src_lstat; - return return_status; + if (return_status != FILE_RETRY) + return return_status; } if (mc_lstat (d, &dst_stats) == 0) { @@ -1181,7 +1180,7 @@ move_file_file (FileOpContext *ctx, char *s, char *d, #if 0 /* Comparison to EXDEV seems not to work in nfs if you're moving from one nfs to the same, but on the server it is on two different - filesystems. Then nfs returns EIO instead of EXDEV. + filesystems. Then nfs returns EIO instead of EXDEV. Hope it will not hurt if we always in case of error try to copy/delete. */ else errno = EXDEV; /* Hack to copy (append) the file and then delete it */