int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0;
zend_string *opened_path = NULL;
char *lock_name;
+#ifdef PHP_WIN32
+ zend_bool restarted = 0;
+#endif
if (ac < 2) {
WRONG_PARAM_COUNT;
lock_mode = (lock_flag & DBA_LOCK_WRITER) ? LOCK_EX : 0;
file_mode = "r+b";
break;
- case 'c':
+ case 'c': {
+#ifdef PHP_WIN32
+ php_stream_statbuf ssb;
+ zend_bool need_creation = 0;
+
+ if (hptr->flags & (DBA_NO_APPEND|DBA_CAST_AS_FD)) {
+ need_creation = (SUCCESS != php_stream_stat_path(Z_STRVAL(args[0]), &ssb));
+ }
+#endif
modenr = DBA_CREAT;
lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0;
if (lock_mode) {
* when the lib opens the file it is already created
*/
file_mode = "r+b"; /* read & write, seek 0 */
+#ifdef PHP_WIN32
+ if (!need_creation) {
+ lock_file_mode = "r+b";
+ } else
+#endif
lock_file_mode = "a+b"; /* append */
} else {
+#ifdef PHP_WIN32
+ if (!need_creation) {
+ file_mode = "r+b";
+ } else
+#endif
file_mode = "a+b"; /* append */
lock_file_mode = "w+b"; /* create/truncate */
}
} else {
+#ifdef PHP_WIN32
+ if (!need_creation) {
+ file_mode = "r+b";
+ } else
+#endif
file_mode = "a+b";
}
/* In case of the 'a+b' append mode, the handler is responsible
* to handle any rewind problems (see flatfile handler).
*/
break;
+ }
case 'n':
modenr = DBA_TRUNC;
lock_mode = (lock_flag & DBA_LOCK_TRUNC) ? LOCK_EX : 0;
}
}
+#ifdef PHP_WIN32
+restart:
+#endif
if (!error && lock_mode) {
if (lock_dbf) {
lock_name = Z_STRVAL(args[0]);
} else if (modenr == DBA_CREAT) {
int flags = fcntl(info->fd, F_GETFL);
fcntl(info->fd, F_SETFL, flags & ~O_APPEND);
+#elif defined(PHP_WIN32)
+ } else if (modenr == DBA_CREAT && !restarted) {
+ zend_bool close_both;
+
+ close_both = (info->fp != info->lock.fp);
+ php_stream_close(info->lock.fp);
+ if (close_both) {
+ php_stream_close(info->fp);
+ }
+ info->fp = NULL;
+ info->lock.fp = NULL;
+ info->fd = -1;
+
+ pefree(info->lock.name, persistent);
+
+ lock_file_mode = "r+b";
+
+ restarted = 1;
+ goto restart;
#endif
}
--- /dev/null
+--TEST--
+Bug #72885 flatfile: dba_fetch() fails to read replaced entry
+--SKIPIF--
+<?php
+$handler = "flatfile";
+require_once(dirname(__FILE__) .'/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__) .'/test.inc');
+
+$db = dba_open($db_filename, 'c', 'flatfile');
+dba_insert('foo', 'bar', $db);
+var_dump(dba_replace('foo', 'baz', $db));
+var_dump(dba_fetch('foo', $db));
+dba_close($db);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__) .'/clean.inc');
+?>
+--EXPECT--
+bool(true)
+string(3) "baz"
+===DONE===