Skip to content

Commit 44ff944

Browse files
committed
Merge branch 'dba'
* dba: fix bug #62490 more test fixes fix test fix php_stream_copy_to_stream_ex usage add missing clean section remove test for already removed feature
2 parents de3b9bc + 5a420c8 commit 44ff944

File tree

10 files changed

+91
-58
lines changed

10 files changed

+91
-58
lines changed

ext/dba/dba_inifile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ DBA_EXISTS_FUNC(inifile)
124124
DBA_DELETE_FUNC(inifile)
125125
{
126126
int res;
127+
zend_bool found = 0;
127128

128129
INIFILE_DATA;
129130
INIFILE_GKEY;
130131

131-
res = inifile_delete(dba, &ini_key TSRMLS_CC);
132+
res = inifile_delete_ex(dba, &ini_key, &found TSRMLS_CC);
132133

133134
INIFILE_DONE;
134-
return (res == -1 ? FAILURE : SUCCESS);
135+
return (res == -1 || !found ? FAILURE : SUCCESS);
135136
}
136137

137138
DBA_FIRSTKEY_FUNC(inifile)

ext/dba/libinifile/inifile.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
402402
return FAILURE;
403403
}
404404
php_stream_seek(dba->fp, pos_start, SEEK_SET);
405-
if (!php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) {
405+
if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) {
406406
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy group [%zu - %zu] to temporary stream", pos_start, pos_end);
407407
return FAILURE;
408408
}
@@ -413,7 +413,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
413413
/* {{{ inifile_filter
414414
* copy from to dba while ignoring key name (group must equal)
415415
*/
416-
static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRMLS_DC)
416+
static int inifile_filter(inifile *dba, inifile *from, const key_type *key, zend_bool *found TSRMLS_DC)
417417
{
418418
size_t pos_start = 0, pos_next = 0, pos_curr;
419419
int ret = SUCCESS;
@@ -424,10 +424,13 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
424424
while(inifile_read(from, &ln TSRMLS_CC)) {
425425
switch(inifile_key_cmp(&ln.key, key TSRMLS_CC)) {
426426
case 0:
427+
if (found) {
428+
*found = (zend_bool) 1;
429+
}
427430
pos_curr = php_stream_tell(from->fp);
428431
if (pos_start != pos_next) {
429432
php_stream_seek(from->fp, pos_start, SEEK_SET);
430-
if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
433+
if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
431434
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start);
432435
ret = FAILURE;
433436
}
@@ -446,7 +449,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
446449
}
447450
if (pos_start != pos_next) {
448451
php_stream_seek(from->fp, pos_start, SEEK_SET);
449-
if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
452+
if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
450453
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start);
451454
ret = FAILURE;
452455
}
@@ -458,7 +461,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
458461

459462
/* {{{ inifile_delete_replace_append
460463
*/
461-
static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append TSRMLS_DC)
464+
static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append, zend_bool *found TSRMLS_DC)
462465
{
463466
size_t pos_grp_start=0, pos_grp_next;
464467
inifile *ini_tmp = NULL;
@@ -497,7 +500,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
497500
php_stream_seek(dba->fp, 0, SEEK_END);
498501
if (pos_grp_next != (size_t)php_stream_tell(dba->fp)) {
499502
php_stream_seek(dba->fp, pos_grp_next, SEEK_SET);
500-
if (!php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) {
503+
if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) {
501504
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy remainder to temporary stream");
502505
ret = FAILURE;
503506
}
@@ -516,7 +519,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
516519
if (key->name && strlen(key->name)) {
517520
/* 6 */
518521
if (!append && ini_tmp) {
519-
ret = inifile_filter(dba, ini_tmp, key TSRMLS_CC);
522+
ret = inifile_filter(dba, ini_tmp, key, found TSRMLS_CC);
520523
}
521524

522525
/* 7 */
@@ -538,7 +541,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
538541
if (fp_tmp && php_stream_tell(fp_tmp)) {
539542
php_stream_seek(fp_tmp, 0, SEEK_SET);
540543
php_stream_seek(dba->fp, 0, SEEK_END);
541-
if (!php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) {
544+
if (SUCCESS != php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) {
542545
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Could not copy from temporary stream - ini file truncated");
543546
ret = FAILURE;
544547
}
@@ -563,23 +566,39 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
563566
*/
564567
int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC)
565568
{
566-
return inifile_delete_replace_append(dba, key, NULL, 0 TSRMLS_CC);
569+
return inifile_delete_replace_append(dba, key, NULL, 0, NULL TSRMLS_CC);
570+
}
571+
/* }}} */
572+
573+
/* {{{ inifile_delete_ex
574+
*/
575+
int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found TSRMLS_DC)
576+
{
577+
return inifile_delete_replace_append(dba, key, NULL, 0, found TSRMLS_CC);
567578
}
568579
/* }}} */
569580

570581
/* {{{ inifile_relace
571582
*/
572583
int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC)
573584
{
574-
return inifile_delete_replace_append(dba, key, value, 0 TSRMLS_CC);
585+
return inifile_delete_replace_append(dba, key, value, 0, NULL TSRMLS_CC);
586+
}
587+
/* }}} */
588+
589+
/* {{{ inifile_replace_ex
590+
*/
591+
int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *value, zend_bool *found TSRMLS_DC)
592+
{
593+
return inifile_delete_replace_append(dba, key, value, 0, found TSRMLS_CC);
575594
}
576595
/* }}} */
577596

578597
/* {{{ inifile_append
579598
*/
580599
int inifile_append(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC)
581600
{
582-
return inifile_delete_replace_append(dba, key, value, 1 TSRMLS_CC);
601+
return inifile_delete_replace_append(dba, key, value, 1, NULL TSRMLS_CC);
583602
}
584603
/* }}} */
585604

ext/dba/libinifile/inifile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC);
4949
int inifile_firstkey(inifile *dba TSRMLS_DC);
5050
int inifile_nextkey(inifile *dba TSRMLS_DC);
5151
int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC);
52+
int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found TSRMLS_DC);
5253
int inifile_replace(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC);
54+
int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *val, zend_bool *found TSRMLS_DC);
5355
int inifile_append(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC);
5456
char *inifile_version();
5557

ext/dba/tests/bug62490.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug #62490 (dba_delete returns true on missing item (inifile))
3+
--SKIPIF--
4+
<?php
5+
$handler = "inifile";
6+
include "skipif.inc";
7+
?>
8+
--FILE--
9+
<?php
10+
$handler = "inifile";
11+
include "test.inc";
12+
13+
$dba = dba_open($db_filename, "n", $handler)
14+
or die;
15+
for ($i = 0; $i < 3; ++$i) {
16+
echo "insert $i:";
17+
var_dump(dba_insert("a", $i, $dba));
18+
}
19+
20+
echo "exists:";
21+
var_dump(dba_exists("a", $dba));
22+
echo "delete:";
23+
var_dump(dba_delete("a", $dba));
24+
echo "exists:";
25+
var_dump(dba_exists("a", $dba));
26+
echo "delete:";
27+
var_dump(dba_delete("a", $dba));
28+
29+
?>
30+
===DONE===
31+
--CLEAN--
32+
<?php
33+
include "clean.inc";
34+
?>
35+
--EXPECT--
36+
insert 0:bool(true)
37+
insert 1:bool(true)
38+
insert 2:bool(true)
39+
exists:bool(true)
40+
delete:bool(true)
41+
exists:bool(false)
42+
delete:bool(false)
43+
===DONE===

ext/dba/tests/dba_db4_003.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ require(dirname(__FILE__) .'/clean.inc');
3939
database handler: db4
4040
int(14)
4141

42-
Notice: dba_open(): %stest0.dbm: unexpected file type or format in %sdba_db4_003.php on line %d
43-
4442
Warning: dba_open(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_003.php on line %d
4543
Error creating %stest0.dbm
4644
Dummy contents

ext/dba/tests/dba_db4_007.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@ require(dirname(__FILE__) .'/clean.inc');
3535
database handler: db4
3636
int(14)
3737

38-
Notice: dba_popen(): %stest0.dbm: unexpected file type or format in %sdba_db4_007.php on line %d
39-
4038
Warning: dba_popen(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_007.php on line %d
4139
Error creating %stest0.dbm

ext/dba/tests/dba_db4_010.phpt

Lines changed: 0 additions & 38 deletions
This file was deleted.

ext/dba/tests/dba_handler.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ do {
8282
dba_close($dba_reader);
8383
}
8484
if (($db_file = dba_popen($db_filename, 'r'.($lock_flag==''?'':'-'), $handler))!==FALSE) {
85-
if ($handler == 'dbm') {
85+
if ($handler == 'dbm' || $handler == "tcadb") {
8686
dba_close($db_file);
8787
}
8888
}

ext/dba/tests/dba_inifile.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ DBA INIFILE handler test
1212
require_once dirname(__FILE__) .'/dba_handler.inc';
1313
?>
1414
===DONE===
15+
--CLEAN--
16+
<?php
17+
require(dirname(__FILE__) .'/clean.inc');
18+
?>
1519
--EXPECT--
1620
database handler: inifile
1721
3NYNYY
1822
Content String 2
1923
Content 2 replaced
2024
Read during write: not allowed
2125
"key number 6" written
22-
Failed to write "key number 6" 2nd time
26+
"key number 6" written 2nd time
2327
Content 2 replaced 2nd time
2428
The 6th value
2529
array(3) {
@@ -36,7 +40,7 @@ Content String 2
3640
Content 2 replaced
3741
Read during write: not allowed
3842
"key number 6" written
39-
Failed to write "key number 6" 2nd time
43+
"key number 6" written 2nd time
4044
Content 2 replaced 2nd time
4145
The 6th value
4246
array(3) {

ext/dba/tests/dba_tcadb.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ DBA TCADB handler test
1616
require_once dirname(__FILE__) .'/dba_handler.inc';
1717
?>
1818
===DONE===
19+
--CLEAN--
20+
<?php
21+
$db_filename = $db_file = dirname(__FILE__) .'/test0.tch';
22+
@unlink($db_filename);
23+
@unlink($db_filename.'.lck');
24+
?>
1925
--EXPECT--
2026
database handler: tcadb
2127
3NYNYY

0 commit comments

Comments
 (0)