Adapt test case to trigger a bug reported by Oliver Kaiser, and
fix the bug.

--HG--
branch : HEAD
diff --git a/lib/zip_replace.c b/lib/zip_replace.c
index c444e78..3f96e5e 100644
--- a/lib/zip_replace.c
+++ b/lib/zip_replace.c
@@ -72,11 +72,15 @@
 	idx = za->nentry - 1;
     }
     
+    if (name && _zip_set_name(za, idx, name) != 0) {
+	za->nentry--;
+	return -1;
+    }
+
+    /* does not change any name related data, so we can do it here;
+     * needed for a double add of the same file name */
     _zip_unchange_data(za->entry+idx);
 
-    if (name && _zip_set_name(za, idx, name) != 0)
-	return -1;
-    
     za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry)
 			    ? ZIP_ST_ADDED : ZIP_ST_REPLACED);
     za->entry[idx].source = source;
diff --git a/regress/add_from_file.c b/regress/add_from_file.c
index f770666..7c72a27 100644
--- a/regress/add_from_file.c
+++ b/regress/add_from_file.c
@@ -53,6 +53,7 @@
     char buf[100];
     int err;
     int i;
+    int ret = 0;
 
     prg = argv[0];
 
@@ -75,7 +76,8 @@
 	if ((zs=zip_source_file(za, file, 0, -1)) == NULL) {
 	    fprintf(stderr, "error creating file source for `%s': %s\n",
 		    file, zip_strerror(za));
-	    return 1;
+	    ret = 1;
+	    continue;
 	}
 
 	if ((name=strrchr(file, '/')) == NULL)
@@ -85,7 +87,7 @@
 	    zip_source_free(zs);
 	    fprintf(stderr, "can't add file `%s': %s\n",
 		    file, zip_strerror(za));
-	    return 1;
+	    ret = 1;
 	}
     }
 
@@ -95,5 +97,5 @@
 	return 1;
     }
 
-    return 0;
+    return ret;
 }
diff --git a/regress/add_from_file_twice_duplicate.test b/regress/add_from_file_twice_duplicate.test
index 94528cb..287624c 100644
--- a/regress/add_from_file_twice_duplicate.test
+++ b/regress/add_from_file_twice_duplicate.test
@@ -3,4 +3,5 @@
 return 1
 args testfile.zip testfile.txt testfile.txt
 file testfile.txt testfile.txt testfile.txt
+file-new testfile.zip testfile.zip
 stderr can't add file `testfile.txt': File already exists