[BusyBox-cvs] busybox/networking ftpgetput.c,1.4,1.5

Glenn McGrath bug1 at busybox.net
Wed Dec 18 02:47:44 UTC 2002


Update of /var/cvs/busybox/networking
In directory winder:/tmp/cvs-serv3938/networking

Modified Files:
	ftpgetput.c 
Log Message:
When retrieving a file dont open file until we have to to prevent files of size 0 being created when retrieval fails, bug found by Jeff Angielski


Index: ftpgetput.c
===================================================================
RCS file: /var/cvs/busybox/networking/ftpgetput.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ftpgetput.c	13 Dec 2002 08:20:44 -0000	1.4
+++ ftpgetput.c	18 Dec 2002 02:47:40 -0000	1.5
@@ -174,16 +174,9 @@
 		filesize = atol(buf + 4);
 	}
 
-	/* only make a local file if we know that one exists on the remote server */
-	if (do_continue) {
-		fd_local = xopen(local_file, O_APPEND | O_WRONLY);
-	} else {
-		fd_local = xopen(local_file, O_CREAT | O_TRUNC | O_WRONLY);
-	}
-
 	if (do_continue) {
 		struct stat sbuf;
-		if (fstat(fd_local, &sbuf) < 0) {
+		if (lstat(local_file, &sbuf) < 0) {
 			perror_msg_and_die("fstat()");
 		}
 		if (sbuf.st_size > 0) {
@@ -204,6 +197,13 @@
 
 	if (ftpcmd("RETR ", server_path, control_stream, buf) > 150) {
 		error_msg_and_die("RETR error: %s", buf + 4);
+	}
+
+	/* only make a local file if we know that one exists on the remote server */
+	if (do_continue) {
+		fd_local = xopen(local_file, O_APPEND | O_WRONLY);
+	} else {
+		fd_local = xopen(local_file, O_CREAT | O_TRUNC | O_WRONLY);
 	}
 
 	/* Copy the file */




More information about the busybox-cvs mailing list