socsvn commit: r256171 - in soc2013/ambarisha/head/usr.bin: dmget dms

ambarisha at FreeBSD.org ambarisha at FreeBSD.org
Mon Aug 19 20:52:57 UTC 2013


Author: ambarisha
Date: Mon Aug 19 20:52:56 2013
New Revision: 256171
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256171

Log:
  Handling download failures (file not found, access denied etc.) with grace
  

Modified:
  soc2013/ambarisha/head/usr.bin/dmget/dmget.c
  soc2013/ambarisha/head/usr.bin/dms/mirror.c
  soc2013/ambarisha/head/usr.bin/dms/worker.c

Modified: soc2013/ambarisha/head/usr.bin/dmget/dmget.c
==============================================================================
--- soc2013/ambarisha/head/usr.bin/dmget/dmget.c	Mon Aug 19 20:51:29 2013	(r256170)
+++ soc2013/ambarisha/head/usr.bin/dmget/dmget.c	Mon Aug 19 20:52:56 2013	(r256171)
@@ -423,6 +423,7 @@
 				rm_dmres(&dmres);
 				goto success;
 			} else {
+				fprintf(stderr, "dmget: download failed: %s\n", dmres->errstr);
 				rm_dmres(&dmres);
 				goto failure;
 			}
@@ -456,6 +457,7 @@
 	ret = -1;
 	goto done;
 failure:
+	remove(dmreq.path);
 	ret = 1;
 	goto done;
 success:

Modified: soc2013/ambarisha/head/usr.bin/dms/mirror.c
==============================================================================
--- soc2013/ambarisha/head/usr.bin/dms/mirror.c	Mon Aug 19 20:51:29 2013	(r256170)
+++ soc2013/ambarisha/head/usr.bin/dms/mirror.c	Mon Aug 19 20:52:56 2013	(r256171)
@@ -203,7 +203,7 @@
 		return -1;
 	}
 
-	while(mirror != NULL) {
+	while(mirrors != NULL) {
 		write_mirror(mirror, f);	
 		mirrors = rm_mirror(mirrors, mirror);
 	}

Modified: soc2013/ambarisha/head/usr.bin/dms/worker.c
==============================================================================
--- soc2013/ambarisha/head/usr.bin/dms/worker.c	Mon Aug 19 20:51:29 2013	(r256170)
+++ soc2013/ambarisha/head/usr.bin/dms/worker.c	Mon Aug 19 20:52:56 2013	(r256171)
@@ -753,10 +753,7 @@
 	tmpreq.path = (char *) malloc(strlen(dmreq->path) + strlen(TMP_EXT));
 	if (tmpreq.path == NULL) {
 		fprintf(stderr, "dmXGet: Insufficient memory\n");
-		free(tmpreq.i_filename);
-		free(tmpreq.path);
-		free(tmpreq.URL);
-		return NULL;
+		goto done;
 	}
 	strcpy(tmpreq.path, dmreq->path);
 	strcat(tmpreq.path, TMP_EXT);
@@ -764,11 +761,19 @@
 	tmpjob.ofd = open(tmpreq.path, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
 
 	FILE *f = fetchXGet(tmpjob.url, us, flags);
+	if (f == NULL) {
+		close(tmpjob.ofd);
+		remove(tmpreq.path);
+		fprintf(stderr, "dmXGet: Couldn't fetch remote file\n");//, fetchLastErrStr);
+		goto done;
+	}
+
 	fetch(&tmpjob, f, *us);
 	fclose(f);
 
 	f = fopen(tmpreq.path, "r");
 
+done:
 	free(tmpjob.url->doc);
 	free(tmpjob.url);
 	free(tmpreq.i_filename);


More information about the svn-soc-all mailing list