]> granicus.if.org Git - php/commitdiff
add crc checked flag, for slight speedup on multiple access to the same file
authorGreg Beaver <cellog@php.net>
Sat, 10 Dec 2005 00:00:00 +0000 (00:00 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 10 Dec 2005 00:00:00 +0000 (00:00 +0000)
ext/phar/phar.c
ext/phar/php_phar.h
ext/phar/tests/013.phpt

index aa77831aac495caa0fd6e79320bd9277f4ffc997..38104e1488dd19d973034b7a537515120aef5e43 100644 (file)
@@ -260,6 +260,7 @@ PHP_METHOD(PHP_Archive, mapPhar)
                PHAR_GET_VAL(entry.timestamp)
                PHAR_GET_VAL(entry.offset_within_phar)
                PHAR_GET_VAL(entry.compressed_filesize)
+               entry.crc_checked = 0;
                if (entry.compressed_filesize < 9) {
                        MAPPHAR_FAIL("internal corruption of phar \"%s\" (file size in phar is not large enough)")
                }
@@ -672,16 +673,19 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe
                        php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
                }
                /* check crc32/filesize */
-               status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, crc32, 0);
-               if (-1 == status) {
-                       PHAR_ZLIB_ERROR
-                                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file);
-                       return NULL;
-               }
-               if (-2 == status) {
-                       PHAR_ZLIB_ERROR
-                                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
-                       return NULL;
+               if (!idata->internal_file->crc_checked) {
+                       status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, crc32, 0);
+                       if (-1 == status) {
+                               PHAR_ZLIB_ERROR
+                                               php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file);
+                               return NULL;
+                       }
+                       if (-2 == status) {
+                               PHAR_ZLIB_ERROR
+                                               php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
+                               return NULL;
+                       }
+                       idata->internal_file->crc_checked = 1;
                }
 #else
                php_error_docref(NULL TSRMLS_CC, E_ERROR, "zlib extension must be enabled for compressed .phar files");
@@ -700,20 +704,23 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe
                }
                php_stream_close(fp);
                /* check length, crc32 */
-               status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, 0, 1);
-               if (-1 == status) {
-                       efree(idata->file);
-                       buffer = idata->data->file;
-                       efree(idata);
-                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file);
-                       return NULL;
-               }
-               if (-2 == status) {
-                       efree(idata->file);
-                       buffer = idata->data->file;
-                       efree(idata);
-                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
-                       return NULL;
+               if (!idata->internal_file->crc_checked) {
+                       status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, 0, 1);
+                       if (-1 == status) {
+                               efree(idata->file);
+                               buffer = idata->data->file;
+                               efree(idata);
+                               php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file);
+                               return NULL;
+                       }
+                       if (-2 == status) {
+                               efree(idata->file);
+                               buffer = idata->data->file;
+                               efree(idata);
+                               php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
+                               return NULL;
+                       }
+                       idata->internal_file->crc_checked = 1;
                }
                memmove(idata->file, idata->file + 8, idata->internal_file->uncompressed_filesize);
        }
index d160e636696d2aec0f5f4661d5eb1b3f79df2e84..3cbf2b6203a07daaf6aa11fd48a95dfdefc647a2 100644 (file)
@@ -53,6 +53,7 @@ typedef struct _phar_manifest_entry {
        php_uint32      timestamp;
        php_uint32      offset_within_phar;
        php_uint32      compressed_filesize;
+       zend_bool       crc_checked;
 } phar_manifest_entry;
 
 typedef struct _phar_file_data {
index d4d08985a5bb3ada71abad4f11d8125647df253e..94d109912ee416d21f311ae02178fad67915ac2e 100644 (file)
@@ -9,7 +9,7 @@ register_shutdown_function('cleanup');
 $file = "<?php
 PHP_Archive::mapPhar(5, 'hio', false);
 __HALT_COMPILER(); ?>";
-// compressed file length does not include 8 bytes for crc/file length and should
+// filesize should be 1, and is 2
 $manifest = pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
 $file .= pack('VV', strlen($manifest) + 4, 1) . $manifest . pack('VV', crc32('a'), 2) . 'a';
 file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);