From roberte@ghost.mep.ruhr-uni-bochum.de  Sat Dec  7 17:42:47 1996
Received: from ghost.mep.ruhr-uni-bochum.de (ghost.mep.ruhr-uni-bochum.de [134.147.6.16])
          by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id RAA20046
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 7 Dec 1996 17:42:45 -0800 (PST)
Received: (from roberte@localhost) by ghost.mep.ruhr-uni-bochum.de (8.7.5/8.7.3) id CAA27684; Sun, 8 Dec 1996 02:42:40 +0100 (MET)
Message-Id: <199612080142.CAA27684@ghost.mep.ruhr-uni-bochum.de>
Date: Sun, 8 Dec 1996 02:42:40 +0100 (MET)
From: Robert Eckardt <roberte@mep.ruhr-uni-bochum.de>
Reply-To: roberte@mep.ruhr-uni-bochum.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: fetch in 2.1.5R doesn't keep interrupted files and sets wrong mirror date
X-Send-Pr-Version: 3.2

>Number:         2170
>Category:       bin
>Synopsis:       fetch in 2.1.5R doesn't keep interrupted files and sets wrong mirror date
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jmg
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec  7 17:50:01 PST 1996
>Closed-Date:    Mon Feb 24 00:32:38 PST 1997
>Last-Modified:  Mon Feb 24 00:33:52 PST 1997
>Originator:     Robert Eckardt
>Release:        FreeBSD 2.1.5-RELEASE i386
>Organization:
>Environment:

	2.1.5-R as of WC-CD

>Description:

	I missed the ability in fetch to keep the transfered file, when
	the transfer was interrupted. However, e.g. for .txt or .pdf files
	it makes sense to have a look at the file. For ftp one could use
	-r or -m but nothing for http. Thus, added an option -k. Man updated.
	Found a bug in -m: After successful transfer time was *not* set to
	that of original file, on interruption only when not -m was specified.
	Fixed.

>How-To-Repeat:

	see description

>Fix:
	Diff to 2.1.5-R source appended below.
	Changed rm() to cleanup() -- seems more appropriate.
	( Not that it would help very much:
	  2:25 ghost: /home/re 0% fetch -k http://www.intel.com/design/pro/manuals/242690_1.pdf
	  Receiving 242690_1.pdf (4463572 bytes): 12%fetch: Timeout
	  2:31 ghost: /home/re 1% ll 242690_1.pdf
	  -rw-rw-r--  1 roberte  work  571088  8 Dez 02:31 242690_1.pdf
	[..]
	  Error (1024): PDF version 1.2 -- xpdf supports version 1.1 (continuing anyway)
	  Error (0): Couldn't read xref table
	)

diff -ru1 usr/src/usr.bin/fetch.old/fetch.1 usr/src/usr.bin/fetch/fetch.1
--- usr/src/usr.bin/fetch.old/fetch.1	Thu Jul  4 13:04:10 1996
+++ usr/src/usr.bin/fetch/fetch.1	Sat Dec  7 01:32:16 1996
@@ -68,2 +68,4 @@
 for transfer.
+.It Fl k
+Keep. Doesn't remove file when transfer was interrupted.
 .It Fl q
diff -ru1 usr/src/usr.bin/fetch.old/main.c usr/src/usr.bin/fetch/main.c
--- usr/src/usr.bin/fetch.old/main.c	Thu Jul  4 12:25:31 1996
+++ usr/src/usr.bin/fetch/main.c	Sun Dec  8 00:24:48 1996
@@ -66,2 +66,3 @@
 int restart = 0;
+int keep = 0;
 time_t modtime;
@@ -70,3 +71,3 @@
 
-void usage (), die (), rm (), t_out (), ftpget (), httpget (),
+void usage (), die (), cleanup (), t_out (), ftpget (), httpget (),
     display (int, int), parse (char *), output_file_name(),
@@ -79,3 +80,3 @@
 {
-    fprintf (stderr, "usage: %s [-D:HINPMV:Lqpr] [-o outputfile] <-f file -h host [-c dir]| URL>\n", progname);
+    fprintf (stderr, "usage: %s [-D:HINPMV:Lkqpr] [-o outputfile] <-f file -h host [-c dir]| URL>\n", progname);
     exit (1);
@@ -87,3 +88,3 @@
 	int e = errno;
-	rm ();
+	cleanup ();
 	if (errno)
@@ -96,3 +97,3 @@
 void
-rm ()
+cleanup ()
 {
@@ -102,5 +103,5 @@
 		if (file != stdout) {
-			if (!restart && !mirror)
+			if (!restart && !mirror && !keep)
 			    remove (outputfile);
-			else if (!mirror) {
+			else if (mirror) {
 				tv[0].tv_usec = tv[1].tv_usec = 0;
@@ -122,3 +123,3 @@
 
-	while ((c = getopt (argc, argv, "D:HINPMV:Lqc:f:h:o:pmr")) != EOF) {
+	while ((c = getopt (argc, argv, "D:HINPMV:Lqc:f:h:ko:pmr")) != EOF) {
 		switch (c) {
@@ -142,2 +143,6 @@
 
+		      case 'k':
+			keep = 1;
+			break;
+
 		      case 'o':
@@ -173,3 +178,2 @@
 	}
-
 	if (mirror && restart)
@@ -195,3 +199,3 @@
 	fprintf (stderr, "\n%s: Timeout\n", progname);
-	rm ();
+	cleanup ();
 	exit (1);
@@ -297,3 +301,4 @@
         fclose(fp);
-        fclose(file);
+	keep = 1;
+	cleanup ();
 	display (size, -1);
@@ -456,3 +461,3 @@
 	}
-	rm ();
+	cleanup ();
 	exit (1);
@@ -469,2 +474,3 @@
 	restart = 0;
+	mirror  = 0;
 
@@ -498,3 +504,3 @@
 			fprintf (stderr, "%s: Timeout\n", progname);
-			rm ();
+			cleanup ();
 			exit (1);
@@ -543,3 +549,3 @@
 				fprintf (stderr, "%s fetching failed, header so far:\n%s\n", file_to_get, s);
-				rm ();
+				cleanup ();
 				exit (1);
@@ -575,3 +581,3 @@
 				fprintf (stderr, "Can't decode the header!\n");
-				rm ();
+				cleanup ();
 				exit (1);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->wollman 
Responsible-Changed-By: mpp 
Responsible-Changed-When: Sat Feb 22 21:54:40 PST 1997 
Responsible-Changed-Why:  
wollman did the last major overhaul of fetch. 
Responsible-Changed-From-To: wollman->jmg 
Responsible-Changed-By: jmg 
Responsible-Changed-When: Sun Feb 23 00:59:43 PST 1997 
Responsible-Changed-Why:  
I'll take this, I've been working with fetch... 

I'm pretty sure that both bugs have already been fixed, I'll be checking 
to make sure. 
State-Changed-From-To: open->closed 
State-Changed-By: jmg 
State-Changed-When: Mon Feb 24 00:32:38 PST 1997 
State-Changed-Why:  
both bugs don't exist in current's fetch. 
To keep a file use the -R param. 
>Unformatted:
