]> granicus.if.org Git - php/commitdiff
another attempt to fix unlink()/unset()
authorGreg Beaver <cellog@php.net>
Sun, 7 Jan 2007 19:45:31 +0000 (19:45 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 7 Jan 2007 19:45:31 +0000 (19:45 +0000)
ext/phar/phar.c
ext/phar/tests/delete_in_phar_confirm.phpt

index fa7a426e4cad7bf0dba44761fcc373ca03dd3c99..b1505c6769b134e89e110a6eeb4314a9b3be6e3d 100644 (file)
@@ -1507,9 +1507,19 @@ static inline void phar_set_16(char *buffer, int var) /* {{{ */
 /**
  * Used to save work done on a writeable phar
  */
+static int do_phar_flush(phar_entry_data *data TSRMLS_DC);
 static int phar_flush(php_stream *stream TSRMLS_DC) /* {{{ */
 {
        phar_entry_data *data = (phar_entry_data *)stream->abstract;
+       if (strcmp(stream->mode, "wb") != 0 && strcmp(stream->mode, "w") != 0) {
+               return EOF;
+       }
+       return do_phar_flush(data TSRMLS_CC);
+}
+/* }}} */
+
+static int do_phar_flush(phar_entry_data *data TSRMLS_DC) /* {{{ */
+{
        phar_entry_info *entry;
        int alias_len, fname_len, halt_offset, restore_alias_len;
        char *buffer, *fname, *alias;
@@ -1524,9 +1534,6 @@ static int phar_flush(php_stream *stream TSRMLS_DC) /* {{{ */
        if (PHAR_G(readonly)) {
                return EOF;
        }
-       if (strcmp(stream->mode, "wb") != 0 && strcmp(stream->mode, "w") != 0) {
-               return EOF;
-       }
        newfile = php_stream_fopen_tmpfile();
        if (!data->fp) {
                data->fp = php_stream_open_wrapper(data->phar->fname, "rb", 0, NULL);
@@ -2198,7 +2205,6 @@ static int phar_unlink(php_stream_wrapper *wrapper, char *url, int options, php_
        php_url *resource;
        char *internal_file;
        phar_entry_data *idata;
-       php_stream *fpf;
        
        resource = php_url_parse(url);
 
@@ -2241,13 +2247,12 @@ static int phar_unlink(php_stream_wrapper *wrapper, char *url, int options, php_
                }
        }
        idata->internal_file->flags |= PHAR_ENT_DELETED;
-       /* we need to "flush" the stream to save the newly deleted file on disk */
-       fpf = php_stream_alloc(&phar_ops, idata, NULL, "wb");
-       phar_flush(fpf TSRMLS_CC);
-       php_stream_close(fpf);
-       efree(idata);
        efree(internal_file);
        php_url_free(resource);
+       idata->internal_file = 0;
+       /* we need to "flush" the stream to save the newly deleted file on disk */
+       do_phar_flush(idata TSRMLS_CC);
+       efree(idata);
        return SUCCESS;
 }
 /* }}} */
@@ -2517,6 +2522,7 @@ PHP_METHOD(Phar, offsetUnset)
        char *fname;
        int fname_len;
        phar_entry_info *entry;
+       phar_entry_data *data;
        PHAR_ARCHIVE_OBJECT();
 
        if (PHAR_G(readonly)) {
@@ -2536,6 +2542,14 @@ PHP_METHOD(Phar, offsetUnset)
                        }
                        entry->flags &= ~PHAR_ENT_MODIFIED;
                        entry->flags |= PHAR_ENT_DELETED;
+                       /* we need to "flush" the stream to save the newly deleted file on disk */
+                       data = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
+                       data->phar = phar_obj->arc.archive;
+                       data->fp = 0;
+                       /* internal_file is unused in do_phar_flush, so we won't set it */
+                       do_phar_flush(data TSRMLS_CC);
+                       efree(data);
+                       RETURN_TRUE;
                }
        } else {
                RETURN_FALSE;
index d4a4006a3e96b062f5c34a9bdbbe68de4e8b75f3..57c4ec58f3740f7ac27098468367ebd2487200ae 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Phar: delete a file within a .phar
+Phar: delete a file within a .phar (confirm disk file is changed)
 --SKIPIF--
 <?php if (!extension_loaded("phar")) print "skip"; ?>
 --INI--