From f4ab4949064b2633c4f069c1baebe1f2600633e3 Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Fri, 29 Sep 2023 15:57:13 +0100 Subject: [PATCH] Invalidate path even if the file was deleted Closes GH-12323 --- NEWS | 3 +++ ext/opcache/ZendAccelerator.c | 9 +++++-- .../opcache_invalidate_deleted_file.phpt | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 ext/opcache/tests/opcache_invalidate_deleted_file.phpt diff --git a/NEWS b/NEWS index 317e2abbe99..96064715a6e 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,9 @@ PHP NEWS . Fixed bug GH-12297 (PHP Startup: Invalid library (maybe not a PHP library) 'mysqlnd.so' in Unknown on line). (nielsdos) +- Opcache: + . Fixed opcache_invalidate() on deleted file. (mikhainin) + - PCRE: . Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with JIT enabled gives different result). (nielsdos) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index e1acff2e4e2..429eadf023e 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1322,6 +1322,7 @@ int zend_accel_invalidate(zend_string *filename, bool force) { zend_string *realpath; zend_persistent_script *persistent_script; + zend_bool file_found = true; if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) { return FAILURE; @@ -1330,7 +1331,10 @@ int zend_accel_invalidate(zend_string *filename, bool force) realpath = accelerator_orig_zend_resolve_path(filename); if (!realpath) { - return FAILURE; + //file could have been deleted, but we still need to invalidate it. + //so instead of failing, just use the provided filename for the lookup + realpath = zend_string_copy(filename); + file_found = false; } if (ZCG(accel_directives).file_cache) { @@ -1366,12 +1370,13 @@ int zend_accel_invalidate(zend_string *filename, bool force) file_handle.opened_path = NULL; zend_destroy_file_handle(&file_handle); + file_found = true; } accelerator_shm_read_unlock(); zend_string_release_ex(realpath, 0); - return SUCCESS; + return file_found ? SUCCESS : FAILURE; } static zend_string* accel_new_interned_key(zend_string *key) diff --git a/ext/opcache/tests/opcache_invalidate_deleted_file.phpt b/ext/opcache/tests/opcache_invalidate_deleted_file.phpt new file mode 100644 index 00000000000..53c7cd5b6b9 --- /dev/null +++ b/ext/opcache/tests/opcache_invalidate_deleted_file.phpt @@ -0,0 +1,26 @@ +--TEST-- +opcache_invalidate() should invalidate deleted file +--EXTENSIONS-- +opcache +--INI-- +opcache.enable_cli=1 +opcache.validate_timestamps=0 +--FILE-- + +--EXPECT-- +int(42) +int(42) +bool(false)