delete 0 zipfiles

--HG--
branch : HEAD
diff --git a/lib/zip_close.c b/lib/zip_close.c
index 0087046..736e6b9 100644
--- a/lib/zip_close.c
+++ b/lib/zip_close.c
@@ -33,7 +33,7 @@
 int
 zip_close(struct zip *zf)
 {
-    int i, count, tfd;
+    int i, count, tfd, ret, survivors;
     char *temp;
     FILE *tfp;
     struct zip *tzf;
@@ -43,18 +43,31 @@
 	return _zip_free(zf);
 
     /* look if there really are any changes */
-    count = 0;
+    count = survivors = 0;
     for (i=0; i<zf->nentry; i++) {
-	if (zf->entry[i].state != ZIP_ST_UNCHANGED) {
+	if (zf->entry[i].state != ZIP_ST_UNCHANGED)
 	    count = 1;
+	if (zf->entry[i].state != ZIP_ST_DELETED)
+	    survivors = 1;
+	if (survivors && count)
 	    break;
-	}
     }
 
     /* no changes, all has been unchanged */
     if (count == 0)
 	return _zip_free(zf);
-    
+
+    /* don't create zip files with no entries */
+    if (survivors == 0) {
+	ret = 0;
+	if (zf->zn)
+	    ret = remove(zf->zn);
+	if (!ret)
+	    return _zip_free(zf);
+	_zip_free(zf);
+	return ret;
+    }	       
+	
     temp = (char *)malloc(strlen(zf->zn)+8);
     if (!temp) {
 	zip_err = ZERR_MEMORY;
diff --git a/regress/Makefile.am b/regress/Makefile.am
index 1fd94c5..14efe69 100644
--- a/regress/Makefile.am
+++ b/regress/Makefile.am
@@ -1,5 +1,6 @@
-noinst_PROGRAMS=ziptest buffadd
+noinst_PROGRAMS=ziptest buffadd deltest
 
+deltest_SOURCES=deltest.c
 buffadd_SOURCES=buffadd.c
 ziptest_SOURCES=ziptest.c error.c
 noinst_HEADERS=error.h