[PHP-DOC] cvs: pecl /phar dirstream.c phar_object.c util.c /phar/tests addfuncs.phpt dir.phpt /phar/tests/tar 033.phpt 033a.phpt dir.phpt /phar/tests/zip 033.phpt 033a.phpt dir.phpt

2008-04-09 Thread Greg Beaver
cellog  Wed Apr  9 19:23:30 2008 UTC

  Added files: 
/pecl/phar/testsaddfuncs.phpt 

  Modified files:  
/pecl/phar  dirstream.c phar_object.c util.c 
/pecl/phar/testsdir.phpt 
/pecl/phar/tests/tar033.phpt 033a.phpt dir.phpt 
/pecl/phar/tests/zip033.phpt 033a.phpt dir.phpt 
  Log:
  add addFile/addFromString/addEmptyDir.  API is identical to ext/zip
  [DOC]
  http://cvs.php.net/viewvc.cgi/pecl/phar/dirstream.c?r1=1.13r2=1.14diff_format=u
Index: pecl/phar/dirstream.c
diff -u pecl/phar/dirstream.c:1.13 pecl/phar/dirstream.c:1.14
--- pecl/phar/dirstream.c:1.13  Mon Mar 24 03:01:29 2008
+++ pecl/phar/dirstream.c   Wed Apr  9 19:23:30 2008
@@ -471,7 +471,7 @@
return FAILURE;
}
 
-   if ((e = phar_get_entry_info_dir(phar, resource-path + 1, 
strlen(resource-path + 1), 1, error TSRMLS_CC))) {
+   if ((e = phar_get_entry_info_dir(phar, resource-path + 1, 
strlen(resource-path + 1), 2, error TSRMLS_CC))) {
/* directory exists, or is a subdirectory of an existing file */
efree(e-filename);
efree(e);
@@ -485,6 +485,18 @@
php_url_free(resource);
return FAILURE;
}
+   if ((e = phar_get_entry_info_dir(phar, resource-path + 1, 
strlen(resource-path + 1), 0, error TSRMLS_CC))) {
+   /* entry exists as a file */
+   php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, phar 
error: cannot create directory \%s\ in phar \%s\, file already exists, 
resource-path+1, resource-host);
+   php_url_free(resource);
+   return FAILURE;
+   }
+   if (error) {
+   php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, phar 
error: cannot create directory \%s\ in phar \%s\, %s, resource-path+1, 
resource-host, error);
+   efree(error);
+   php_url_free(resource);
+   return FAILURE;
+   }
 
memset((void *) entry, 0, sizeof(phar_entry_info));
 
@@ -582,7 +594,7 @@
return FAILURE;
}
 
-   if (!(entry = phar_get_entry_info_dir(phar, resource-path + 1, 
strlen(resource-path + 1), 1, error TSRMLS_CC))) {
+   if (!(entry = phar_get_entry_info_dir(phar, resource-path + 1, 
strlen(resource-path + 1), 2, error TSRMLS_CC))) {
if (error) {
php_stream_wrapper_log_error(wrapper, options 
TSRMLS_CC, phar error: cannot remove directory \%s\ in phar \%s\, %s, 
resource-path+1, resource-host, error);
efree(error);
http://cvs.php.net/viewvc.cgi/pecl/phar/phar_object.c?r1=1.195r2=1.196diff_format=u
Index: pecl/phar/phar_object.c
diff -u pecl/phar/phar_object.c:1.195 pecl/phar/phar_object.c:1.196
--- pecl/phar/phar_object.c:1.195   Wed Apr  9 18:12:40 2008
+++ pecl/phar/phar_object.c Wed Apr  9 19:23:30 2008
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: phar_object.c,v 1.195 2008/04/09 18:12:40 cellog Exp $ */
+/* $Id: phar_object.c,v 1.196 2008/04/09 19:23:30 cellog Exp $ */
 
 #include phar_internal.h
 #include func_interceptors.h
@@ -2827,7 +2827,7 @@
return;
}

-   if (!phar_get_entry_info_dir(phar_obj-arc.archive, fname, fname_len, 
2, error TSRMLS_CC)) {
+   if (!phar_get_entry_info_dir(phar_obj-arc.archive, fname, fname_len, 
1, error TSRMLS_CC)) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 
TSRMLS_CC, Entry %s does not exist%s%s, fname, error?, :, error?error:);
} else {
fname_len = spprintf(fname, 0, phar://%s/%s, 
phar_obj-arc.archive-fname, fname);
@@ -2840,44 +2840,21 @@
 }
 /* }}} */
 
-/* {{{ proto int Phar::offsetSet(string entry, string value)
- * set the contents of an internal file to those of an external file
+/* {{{ add a file within the phar archive from a string or resource
  */
-PHP_METHOD(Phar, offsetSet)
+static void phar_add_file(phar_archive_data *phar, char *filename, int 
filename_len, char *cont_str, int cont_len, zval *zresource TSRMLS_DC)
 {
-   char *fname, *cont_str = NULL, *error;
-   int fname_len, cont_len;
-   zval *zresource;
+   char *error;
long contents_len;
phar_entry_data *data;
php_stream *contents_file;
-   PHAR_ARCHIVE_OBJECT();
-
-   if (PHAR_G(readonly)  !phar_obj-arc.archive-is_data) {
-   zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 
TSRMLS_CC, Write operations disabled by INI setting);
-   return;
-   }
-   
-   if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() 
TSRMLS_CC, sr, fname, fname_len, zresource) == FAILURE
-zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ss, fname, 
fname_len, cont_str, cont_len) == FAILURE) {
-   return;
-   }
 
-   if ((phar_obj-arc.archive-is_tar || 

[PHP-DOC] cvs: pecl /phar phar_object.c /phar/tests phar_oo_iswriteable.phpt

2008-04-09 Thread Greg Beaver
cellog  Thu Apr 10 03:32:09 2008 UTC

  Modified files:  
/pecl/phar  phar_object.c 
/pecl/phar/testsphar_oo_iswriteable.phpt 
  Log:
  add Phar-isWritable() for detecting whether a phar archive can be written to 
based on phar.readonly combined with actual file permissions
  [DOC]
  
http://cvs.php.net/viewvc.cgi/pecl/phar/phar_object.c?r1=1.196r2=1.197diff_format=u
Index: pecl/phar/phar_object.c
diff -u pecl/phar/phar_object.c:1.196 pecl/phar/phar_object.c:1.197
--- pecl/phar/phar_object.c:1.196   Wed Apr  9 19:23:30 2008
+++ pecl/phar/phar_object.c Thu Apr 10 03:32:09 2008
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: phar_object.c,v 1.196 2008/04/09 19:23:30 cellog Exp $ */
+/* $Id: phar_object.c,v 1.197 2008/04/10 03:32:09 cellog Exp $ */
 
 #include phar_internal.h
 #include func_interceptors.h
@@ -2094,6 +2094,28 @@
 }
 /* }}} */
 
+/* {{{ proto bool Phar::isWritable()
+ * Returns true if phar.readonly=0 or phar is a PharData AND the actual file 
is writable.
+ */
+PHP_METHOD(Phar, isWritable)
+{
+   php_stream_statbuf ssb;
+   PHAR_ARCHIVE_OBJECT();
+   
+   if (!phar_obj-arc.archive-is_writeable) {
+   RETURN_FALSE;
+   }
+   if (SUCCESS != php_stream_stat_path(phar_obj-arc.archive-fname, 
ssb)) {
+   if (phar_obj-arc.archive-is_brandnew) {
+   /* assume it works if the file doesn't exist yet */
+   RETURN_TRUE;
+   }
+   RETURN_FALSE;
+   }
+   RETURN_BOOL((ssb.sb.st_mode  (S_IWOTH | S_IWGRP | S_IWUSR)) != 0);
+}
+/* }}} */
+
 /* {{{ proto bool Phar::delete(string entry)
  * Deletes a named file within the archive.
  */
@@ -3925,6 +3947,7 @@
PHP_ME(Phar, hasMetadata,   NULL,  
ZEND_ACC_PUBLIC)
PHP_ME(Phar, isBuffering,   NULL,  
ZEND_ACC_PUBLIC)
PHP_ME(Phar, isCompressed,  NULL,  
ZEND_ACC_PUBLIC)
+   PHP_ME(Phar, isWritable,NULL,  
ZEND_ACC_PUBLIC)
PHP_ME(Phar, isPhar,NULL,  
ZEND_ACC_PUBLIC)
PHP_ME(Phar, isTar, NULL,  
ZEND_ACC_PUBLIC)
PHP_ME(Phar, isZip, NULL,  
ZEND_ACC_PUBLIC)
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_oo_iswriteable.phpt?r1=1.1r2=1.2diff_format=u
Index: pecl/phar/tests/phar_oo_iswriteable.phpt
diff -u pecl/phar/tests/phar_oo_iswriteable.phpt:1.1 
pecl/phar/tests/phar_oo_iswriteable.phpt:1.2
--- pecl/phar/tests/phar_oo_iswriteable.phpt:1.1Thu Apr 10 03:12:07 2008
+++ pecl/phar/tests/phar_oo_iswriteable.phptThu Apr 10 03:32:09 2008
@@ -8,6 +8,7 @@
 --FILE--
 ?php
 $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
 $pname = 'phar://hio';
 $file = '?php include ' . $pname . '/a.php; __HALT_COMPILER(); ?';
 
@@ -17,6 +18,9 @@
 $hasdir = 1;
 include 'files/phar_test.inc';
 $a = new Phar($fname);
+$b = new PharData($fname2);
+$b['test'] = 'hi';
+
 var_dump($a['a.php']-isWritable());
 var_dump($a['a.php']-isReadable());
 $a['a.php']-chmod(000);
@@ -34,10 +38,26 @@
 var_dump($a['a.php']-isWritable());
 var_dump($a['a.php']-isReadable());
 ?
+archive
+?php
+ini_set('phar.readonly',0);
+clearstatcache();
+var_dump($a-isWritable());
+var_dump($b-isWritable());
+ini_set('phar.readonly',1);
+clearstatcache();
+var_dump($a-isWritable());
+var_dump($b-isWritable());
+chmod($fname2, 000);
+clearstatcache();
+var_dump($a-isWritable());
+var_dump($b-isWritable());
+?
 ===DONE===
 --CLEAN--
 ?php 
 unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . 
'.1.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
 ?
 --EXPECT--
 bool(true)
@@ -50,4 +70,11 @@
 bool(true)
 bool(true)
 bool(true)
+archive
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
 ===DONE===