PHAR_ENTRY_OBJECT();
if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting");
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by phar.readonly INI setting");
return;
}
if (entry_obj->ent.entry->is_tar) {
"Cannot set metadata, not possible with tar-based phar archives");
return;
}
- if (entry_obj->ent.entry->is_dir) {
+ if (entry_obj->ent.entry->is_temp_dir) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
- "Phar entry is a directory, cannot set metadata"); \
+ "Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata"); \
return;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &metadata) == FAILURE) {
PHAR_ENTRY_OBJECT();
if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting");
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by phar.readonly INI setting");
return;
}
if (entry_obj->ent.entry->is_tar) {
return;
}
if (entry_obj->ent.entry->is_temp_dir) {
- RETURN_FALSE;
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata"); \
+ return;
}
if (entry_obj->ent.entry->metadata) {
zval_ptr_dtor(&entry_obj->ent.entry->metadata);
--- /dev/null
+--TEST--
+Phar: PharFileInfo::setMetadata/delMetadata extra code coverage
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+
+$phar['a/b'] = 'hi there';
+$tar = $phar->convertToData(Phar::TAR);
+
+$b = $phar['a/b'];
+try {
+$tar['a/b']->setMetadata('hi');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$tar['a/b']->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$phar['a']->setMetadata('hi');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$phar['a']->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+ini_set('phar.readonly', 1);
+try {
+$b->setMetadata('hi');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$b->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+ini_set('phar.readonly', 0);
+$b->setMetadata(1,2,3);
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--EXPECTF--
+Cannot set metadata, not possible with tar-based phar archives
+Cannot delete metadata, not possible with tar-based phar archives
+Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata
+Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata
+Write operations disabled by phar.readonly INI setting
+Write operations disabled by phar.readonly INI setting
+
+Warning: PharFileInfo::setMetadata() expects exactly 1 parameter, 3 given in %spharfileinfo_setmetadata.php on line %d
+===DONE===