Index: trunk/xcache.c
===================================================================
--- trunk/xcache.c	(revision 866)
+++ trunk/xcache.c	(revision 867)
@@ -901,6 +901,6 @@
 
 #define XC_INCLUDE_PATH_XSTAT_FUNC(name) zend_bool name(const char *absolute_path, size_t absolute_path_len, void *data TSRMLS_DC)
-typedef XC_INCLUDE_PATH_XSTAT_FUNC((*include_path_xstat_fun_t));
-static zend_bool include_path_xstat(const char *filepath, char *opened_path_buffer, include_path_xstat_fun_t xstat_func, void *data TSRMLS_DC) /* {{{ */
+typedef XC_INCLUDE_PATH_XSTAT_FUNC((*include_path_xstat_func_t));
+static zend_bool xc_include_path_apply(const char *filepath, char *opened_path_buffer, include_path_xstat_func_t xstat_func, void *data TSRMLS_DC) /* {{{ */
 {
 	char *paths, *path;
@@ -963,16 +963,43 @@
 }
 /* }}} */
-static int xc_stat(const char *filepath, char *opened_path_buffer, struct stat *pbuf TSRMLS_DC) /* {{{ */
-{
-	return include_path_xstat(filepath, opened_path_buffer, xc_stat_file, (void *) pbuf TSRMLS_DC)
+static int xc_include_path_stat(const char *filepath, char *opened_path_buffer, struct stat *pbuf TSRMLS_DC) /* {{{ */
+{
+	return xc_include_path_apply(filepath, opened_path_buffer, xc_stat_file, (void *) pbuf TSRMLS_DC)
 		? SUCCESS
 		: FAILURE;
 }
 /* }}} */
-static int xc_entry_php_resolve_opened_path(xc_compiler_t *compiler TSRMLS_DC) /* {{{ */
-{
-	assert(!compiler->opened_path);
-	compiler->opened_path = expand_filepath(compiler->filename, compiler->opened_path_buffer TSRMLS_CC);
-	return SUCCESS;
+typedef struct xc_entry_find_include_path_data_t { /* {{{ */
+	xc_compiler_t *compiler;
+	xc_entry_php_t **stored_entry;
+} xc_entry_find_include_path_data_t;
+/* }}} */
+static XC_INCLUDE_PATH_XSTAT_FUNC(xc_entry_find_include_path_func_dmz) /* {{{ */
+{
+	xc_entry_find_include_path_data_t *entry_find_include_path_data = (xc_entry_find_include_path_data_t *) data;
+	xc_compiler_t *compiler = entry_find_include_path_data->compiler;
+
+	compiler->new_entry.entry.name.str.val = absolute_path;
+	compiler->new_entry.entry.name.str.len = strlen(compiler->new_entry.entry.name.str.val);
+
+	*entry_find_include_path_data->stored_entry = (xc_entry_php_t *) xc_entry_find_dmz(
+			XC_TYPE_PHP
+			, xc_php_caches[compiler->entry_hash.cacheid]
+			, compiler->entry_hash.entryslotid
+			, (xc_entry_t *) &compiler->new_entry
+			TSRMLS_CC);
+
+	return *entry_find_include_path_data->stored_entry ? 1 : 0;
+}
+/* }}} */
+static int xc_entry_find_include_path_dmz(xc_compiler_t *compiler, const char *filepath, char *opened_path_buffer, xc_entry_php_t **stored_entry TSRMLS_DC) /* {{{ */
+{
+	xc_entry_find_include_path_data_t entry_find_include_path_data;
+	entry_find_include_path_data.compiler = compiler;
+	entry_find_include_path_data.stored_entry = stored_entry;
+
+	return xc_include_path_apply(filepath, opened_path_buffer, xc_entry_find_include_path_func_dmz, (void *) &entry_find_include_path_data TSRMLS_DC)
+		? SUCCESS
+		: FAILURE;
 }
 /* }}} */
@@ -1031,5 +1058,5 @@
 
 		if (xc_entry_php_quick_resolve_opened_path(compiler, &buf TSRMLS_CC) != SUCCESS) {
-			if (xc_stat(compiler->filename, compiler->opened_path_buffer, &buf TSRMLS_CC) != SUCCESS) {
+			if (xc_include_path_stat(compiler->filename, compiler->opened_path_buffer, &buf TSRMLS_CC) != SUCCESS) {
 				return FAILURE;
 			}
@@ -1049,5 +1076,7 @@
 #endif
 	}
-	else { /* XG(inode) */
+	else {
+		xc_entry_php_quick_resolve_opened_path(compiler, NULL TSRMLS_CC);
+
 		compiler->new_entry.file_mtime   = 0;
 		compiler->new_entry.file_size    = 0;
@@ -1057,12 +1086,4 @@
 #endif
 	}
-
-	if (!compiler->new_entry.file_inode) {
-		if (!compiler->opened_path) {
-			xc_entry_php_resolve_opened_path(compiler TSRMLS_CC);
-		}
-	}
-
-	fprintf(stderr, "-------- %s\n", compiler->opened_path);
 
 	{
@@ -1821,4 +1842,5 @@
 	xc_sandbox_t sandbox;
 	xc_cache_t *cache = xc_php_caches[compiler->entry_hash.cacheid];
+	struct stat statbuf;
 
 	/* stale clogs precheck */
@@ -1832,19 +1854,28 @@
 	stored_php = NULL;
 
-	if (compiler->opened_path) {
-		compiler->new_entry.entry.name.str.val = (char *) compiler->opened_path;
-		compiler->new_entry.entry.name.str.len = strlen(compiler->new_entry.entry.name.str.val);
-	}
-	else {
-		/* lookup in opened path */
-	}
-
 	ENTER_LOCK_EX(cache) {
-		if (XG(stat)) {
-			stored_entry = (xc_entry_php_t *) xc_entry_find_dmz(XC_TYPE_PHP, cache, compiler->entry_hash.entryslotid, (xc_entry_t *) &compiler->new_entry TSRMLS_CC);
+		if (!compiler->opened_path && xc_entry_find_include_path_dmz(compiler, compiler->filename, compiler->opened_path_buffer, &stored_entry TSRMLS_CC) == SUCCESS) {
+			compiler->opened_path = compiler->opened_path_buffer;
 		}
 		else {
+			if (!compiler->opened_path) {
+				if (xc_entry_php_quick_resolve_opened_path(compiler, NULL TSRMLS_CC) == SUCCESS) {
+					/* opened_path resolved */
+				}
+				/* fall back to real stat call */
+				else if (xc_include_path_stat(compiler->filename, compiler->opened_path_buffer, &statbuf TSRMLS_CC) == SUCCESS) {
+					compiler->opened_path = compiler->opened_path_buffer;
+				}
+				else {
+					gaveup = 1;
+					break;
+				}
+			}
+
+			/* finalize name */
 			compiler->new_entry.entry.name.str.val = (char *) compiler->opened_path;
 			compiler->new_entry.entry.name.str.len = strlen(compiler->new_entry.entry.name.str.val);
+
+			stored_entry = (xc_entry_php_t *) xc_entry_find_dmz(XC_TYPE_PHP, cache, compiler->entry_hash.entryslotid, (xc_entry_t *) &compiler->new_entry TSRMLS_CC);
 		}
 
@@ -1871,7 +1902,4 @@
 			compiler->new_entry.php = stored_php;
 			xc_php_addref_dmz(stored_php);
-			if (!compiler->opened_path) {
-				xc_entry_php_resolve_opened_path(compiler TSRMLS_CC);
-			}
 			xc_entry_php_init(&compiler->new_entry, compiler->opened_path TSRMLS_CC);
 			stored_entry = xc_entry_php_store_dmz(cache, compiler->entry_hash.entryslotid, &compiler->new_entry TSRMLS_CC);
@@ -1898,5 +1926,5 @@
 
 	/* found entry */
-	if (stored_entry) {
+	if (stored_entry && stored_php) {
 		return xc_compile_restore(stored_entry, stored_php, h TSRMLS_CC);
 	}
