]> granicus.if.org Git - php/commitdiff
revert previous changes to tar.c, fix incorrect user_stub == dummy check, now things...
authorGreg Beaver <cellog@php.net>
Sat, 23 Feb 2008 18:09:31 +0000 (18:09 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 23 Feb 2008 18:09:31 +0000 (18:09 +0000)
ext/phar/tar.c

index e95c7237cf691f2143925f4809b95acc1ff94627..a6d8ad5496f5b37027cc4fc5e833440fc5c19a05 100644 (file)
@@ -475,7 +475,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er
        }
 
        /* set stub */
-       if (user_stub && user_stub != "dummy") {
+       if (user_stub && (len < 0 || (len = sizeof("dummy") - 1 && !strncmp(user_stub, "dummy", sizeof("dummy")-1)))) {
                char *pos;
                if (len < 0) {
                        /* resource passed in */
@@ -534,15 +534,12 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er
                }
        } else {
                /* Either this is a brand new phar (add the stub), or setDefaultStub() is the caller (overwrite the stub) */
-               if (zend_hash_exists(&phar->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) {
-                       goto no_default_stub;
-               }
                entry.fp = php_stream_fopen_tmpfile();
                if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) {
+                       php_stream_close(entry.fp);
                        if (error) {
                                spprintf(error, 0, "unable to %s stub in%star-based phar \"%s\", failed", user_stub ? "overwrite" : "create", user_stub ? " " : " new ", phar->fname);
                        }
-                       php_stream_close(entry.fp);
                        return EOF;
                }
                entry.uncompressed_filesize = entry.compressed_filesize = sizeof(newstub) - 1;
@@ -550,13 +547,18 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er
                entry.filename_len = sizeof(".phar/stub.php")-1;
 
                if (!user_stub) {
-                       if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
+                       if (!zend_hash_exists(&phar->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) {
+                               if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
+                                       php_stream_close(entry.fp);
+                                       efree(entry.filename);
+                                       if (error) {
+                                               spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname);
+                                       }
+                                       return EOF;
+                               }
+                       } else {
                                php_stream_close(entry.fp);
                                efree(entry.filename);
-                               if (error) {
-                                       spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname);
-                               }
-                               return EOF;
                        }
                } else {
                        if (SUCCESS != zend_hash_update(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
@@ -569,7 +571,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er
                        }
                }
        }
-no_default_stub:
+
        if (phar->fp && !phar->is_brandnew) {
                oldfile = phar->fp;
                closeoldfile = 0;