bin/144919: [patch] [pkg_install] Remove partially downloaded file on fetch failure

Garrett Cooper gcooper at
Sun Mar 21 01:30:02 UTC 2010

>Number:         144919
>Category:       bin
>Synopsis:       [patch] [pkg_install] Remove partially downloaded file on fetch failure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 21 01:30:01 UTC 2010
>Originator:     Garrett Cooper
>Release:        9-CURRENT
Cisco Systems, Inc.
FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #5 r205310: Sat Mar 20 01:32:51 PDT 2010     gcooper at bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA  amd64
An annoyance I've had to deal with over the past week is that pkg_add -Kr on DNS resolution failure retains dummy 0 byte packages instead of deleting them on fetch failure.

This patch removes the file when the fetch fails.
pkg_add -Kr a_package_that_does_not_exist.tbz
See patch.

Patch attached with submission follows:

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/url.c#1 - /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/lib/url.c ====
@@ -108,6 +108,10 @@
     if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
 	printf("Error: Unable to get %s: %s\n",
 	       fname, fetchLastErrString);
+	/* If the fetch fails, yank the package. */
+	if (keep_package && unlink(pkg) < 0 && Verbose) {
+	    warnx("failed to remove partially fetched package: %s", pkg);
+	}
 	return NULL;


More information about the freebsd-bugs mailing list