From ebd405b5aa022f6dc878c846e3ebeaf133355a32 Mon Sep 17 00:00:00 2001 From: JasWSInc Date: Wed, 24 Dec 2014 13:31:50 -0900 Subject: [PATCH 1/8] Discard iterator references before rename. See: websharks/quick-cache#288 --- quick-cache/includes/share.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index 9308ddf..6e22c59 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -1531,7 +1531,7 @@ public function delete_files_from_cache_dir($regex, $check_max_age = FALSE) throw new \exception(sprintf(__('Unable to delete files. Rename failure on directory: `%1$s`.', $this->text_domain), $cache_dir)); /** @var $_file_dir \RecursiveDirectoryIterator Regex iterator reference for IDEs. */ - foreach($this->dir_regex_iteration($cache_dir_tmp, $cache_dir_tmp_regex) as $_file_dir) + foreach(($_dir_regex_iteration = $this->dir_regex_iteration($cache_dir_tmp, $cache_dir_tmp_regex)) as $_file_dir) { if(($_file_dir->isFile() || $_file_dir->isLink()) // Files and/or symlinks only. @@ -1555,7 +1555,7 @@ public function delete_files_from_cache_dir($regex, $check_max_age = FALSE) # $counter++; // Increment counter for each directory we delete. ~ NO don't do that here. } } - unset($_file_dir); // Housekeeping after this `foreach()` loop. + unset($_dir_regex_iteration, $_file_dir); // Housekeeping after this `foreach()` loop. if(!rename($cache_dir_tmp, $cache_dir)) // Deletions are atomic; restore original directory now. throw new \exception(sprintf(__('Unable to delete files. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $cache_dir_tmp)); @@ -1659,7 +1659,7 @@ public function delete_files_from_host_cache_dir($regex, $check_max_age = FALSE) throw new \exception(sprintf(__('Unable to delete files. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $_host_cache_dir)); /** @var $_file_dir \RecursiveDirectoryIterator Regex iterator reference for IDEs. */ - foreach($this->dir_regex_iteration($_host_cache_dir_tmp, $_host_cache_dir_tmp_regex) as $_file_dir) + foreach(($_dir_regex_iteration = $this->dir_regex_iteration($_host_cache_dir_tmp, $_host_cache_dir_tmp_regex)) as $_file_dir) { if(($_file_dir->isFile() || $_file_dir->isLink()) // Files and/or symlinks only. @@ -1683,7 +1683,7 @@ public function delete_files_from_host_cache_dir($regex, $check_max_age = FALSE) # $counter++; // Increment counter for each directory we delete. ~ NO don't do that here. } } - unset($_file_dir); // Housekeeping after this `foreach()` loop. + unset($_dir_regex_iteration, $_file_dir); // Housekeeping after this `foreach()` loop. if(!rename($_host_cache_dir_tmp, $_host_cache_dir)) // Deletions are atomic; restore original directory now. throw new \exception(sprintf(__('Unable to delete files. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $_host_cache_dir_tmp)); @@ -1741,7 +1741,7 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE) throw new \exception(sprintf(__('Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $dir)); /** @var $_file_dir \RecursiveDirectoryIterator for IDEs. */ - foreach($this->dir_regex_iteration($dir_temp, '/.+/') as $_file_dir) + foreach(($_dir_regex_iteration = $this->dir_regex_iteration($dir_temp, '/.+/')) as $_file_dir) { if(($_file_dir->isFile() || $_file_dir->isLink())) // Files and/or symlinks. { @@ -1756,7 +1756,7 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE) $counter++; // Increment counter for each directory we delete. } } - unset($_file_dir); // Housekeeping after this `foreach()` loop. + unset($_dir_regex_iteration, $_file_dir); // Housekeeping after this `foreach()` loop. if(!rename($dir_temp, $dir)) // Deletions are atomic; restore original directory now. throw new \exception(sprintf(__('Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $dir_temp)); From 7a9153dadbfef43631ce84b00d335d587a763c65 Mon Sep 17 00:00:00 2001 From: JasWSInc Date: Wed, 24 Dec 2014 14:35:31 -0900 Subject: [PATCH 2/8] Clear stat cache before iteration. See: websharks/quick-cache#385 --- quick-cache/includes/share.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index 6e22c59..d0b9e7a 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -1513,6 +1513,8 @@ public function delete_files_from_cache_dir($regex, $check_max_age = FALSE) $cache_lock = $this->cache_lock(); // Lock cache writes. + clearstatcache(); // Clear stat cache to be sure we have a fresh start below. + $cache_dir_tmp = $this->add_tmp_suffix($cache_dir); // Temporary directory. $cache_dir_tmp_regex = $regex; // Initialize host-specific regex pattern for the tmp directory. @@ -1622,6 +1624,8 @@ public function delete_files_from_host_cache_dir($regex, $check_max_age = FALSE) $cache_lock = $this->cache_lock(); // Lock cache writes. + clearstatcache(); // Clear stat cache to be sure we have a fresh start below. + foreach(array('http', 'https') as $_host_scheme) // Consider `http|https` schemes. /* This multi-scheme iteration could (alternatively) be accomplished via regex `\/https?\/`. @@ -1737,6 +1741,8 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE) $cache_lock = $this->cache_lock(); // Lock cache writes. + clearstatcache(); // Clear stat cache to be sure we have a fresh start below. + if(!rename($dir, $dir_temp)) // Work from tmp directory so deletions are atomic. throw new \exception(sprintf(__('Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $dir)); From de2148fd0cda544247337cfa8afc6d2881dc1724 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Sat, 27 Dec 2014 15:31:36 -0500 Subject: [PATCH 3/8] Add filter to allow cache locking to be disabled. See websharks/quick-cache#387 --- quick-cache/includes/share.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index d0b9e7a..64ec91f 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -1789,7 +1789,7 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE) * * @since 140422 First documented version. * - * @return array Lock type & resource handle needed to unlock later. + * @return array Lock type & resource handle needed to unlock later or FALSE if disabled by filter. * * @throws \exception If {@link \sem_get()} not available and there's * no writable tmp directory for {@link \flock()} either. @@ -1801,6 +1801,9 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE) */ public function cache_lock() { + if((boolean)apply_filters('quick_cache_disable_cache_locking', FALSE)) + return false; + if(!($wp_config_file = $this->find_wp_config_file())) throw new \exception(__('Unable to find the wp-config.php file.', $this->text_domain)); @@ -1831,6 +1834,9 @@ public function cache_lock() */ public function cache_unlock(array $lock) { + if((boolean)apply_filters('quick_cache_disable_cache_locking', FALSE)) + return; + if(!is_array($lock)) return; // Not possible. From 16b672b4033dc092e225d1eabc3e1a3cc1a1d7ab Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Sat, 27 Dec 2014 16:34:23 -0500 Subject: [PATCH 4/8] Add new filter to allow site owner to specify cache locking method. See websharks/quick-cache#387 --- quick-cache/includes/share.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index 64ec91f..f2d7cdf 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -1807,12 +1807,18 @@ public function cache_lock() if(!($wp_config_file = $this->find_wp_config_file())) throw new \exception(__('Unable to find the wp-config.php file.', $this->text_domain)); - if($this->function_is_possible('sem_get')) - if(($ipc_key = ftok($wp_config_file, 'w'))) - if(($resource = sem_get($ipc_key, 1)) && sem_acquire($resource)) - return array('type' => 'sem', 'resource' => $resource); + $locking_method = apply_filters('quick_cache_cache_locking_method', 'flock'); - // Use `flock()` as a decent fallback when `sem_get()` is not possible. + if(!in_array($locking_method, array('flock', 'sem'))) + $locking_method = 'flock'; + + if($locking_method === 'sem') + if($this->function_is_possible('sem_get')) + if(($ipc_key = ftok($wp_config_file, 'w'))) + if(($resource = sem_get($ipc_key, 1)) && sem_acquire($resource)) + return array('type' => 'sem', 'resource' => $resource); + + // Use `flock()` as a decent fallback when `sem_get()` is not not forced or is not possible. if(!($tmp_dir = $this->get_tmp_dir())) throw new \exception(__('No writable tmp directory.', $this->text_domain)); From 42ec2104607330f2860a35ad5fee1e5310384290 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Sun, 28 Dec 2014 15:16:32 -0500 Subject: [PATCH 5/8] Improve new cache lock filter names as per Jason's feedback. See websharks/quick-cache#388 --- quick-cache/includes/share.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index f2d7cdf..4852c82 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -1801,13 +1801,13 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE) */ public function cache_lock() { - if((boolean)apply_filters('quick_cache_disable_cache_locking', FALSE)) + if($this->apply_filters(__CLASS__.'_disable_cache_locking', FALSE)) return false; if(!($wp_config_file = $this->find_wp_config_file())) throw new \exception(__('Unable to find the wp-config.php file.', $this->text_domain)); - $locking_method = apply_filters('quick_cache_cache_locking_method', 'flock'); + $locking_method = $this->apply_filters(__METHOD__.'_lock_type', 'flock'); if(!in_array($locking_method, array('flock', 'sem'))) $locking_method = 'flock'; @@ -1840,7 +1840,7 @@ public function cache_lock() */ public function cache_unlock(array $lock) { - if((boolean)apply_filters('quick_cache_disable_cache_locking', FALSE)) + if($this->apply_filters(__CLASS__.'_disable_cache_locking', FALSE)) return; if(!is_array($lock)) From d87a42d04b8d79dfe4f0db88d2237e41d4dfd12b Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Mon, 29 Dec 2014 23:23:03 -0500 Subject: [PATCH 6/8] Releasing Quick Cache v141229 (Release Candidate) --- quick-cache/includes/share.php | 2 +- quick-cache/quick-cache.php | 2 +- quick-cache/readme.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index 4852c82..b067a8a 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -52,7 +52,7 @@ abstract class share // Shared between {@link advanced_cache} and {@link plugin} * * @var string Current version of the software. */ - public $version = '141205'; + public $version = '141229'; /** * Plugin slug; based on `__NAMESPACE__`. diff --git a/quick-cache/quick-cache.php b/quick-cache/quick-cache.php index 1c03893..7f7c72a 100644 --- a/quick-cache/quick-cache.php +++ b/quick-cache/quick-cache.php @@ -1,6 +1,6 @@ Date: Wed, 31 Dec 2014 17:36:09 -0500 Subject: [PATCH 7/8] Update default language files in preparation for v141231 --- .../includes/translations/quick-cache.pot | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/quick-cache/includes/translations/quick-cache.pot b/quick-cache/includes/translations/quick-cache.pot index 09a74af..4e486a6 100644 --- a/quick-cache/includes/translations/quick-cache.pot +++ b/quick-cache/includes/translations/quick-cache.pot @@ -2,9 +2,9 @@ # This file is distributed under the same license as the Quick Cache package. msgid "" msgstr "" -"Project-Id-Version: Quick Cache 141205\n" +"Project-Id-Version: Quick Cache 141231\n" "Report-Msgid-Bugs-To: http://wordpress.org/tag/quick-cache\n" -"POT-Creation-Date: 2014-12-05 05:37:06+00:00\n" +"POT-Creation-Date: 2014-12-31 22:32:49+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -1036,65 +1036,65 @@ msgstr "" msgid "Unable to determine cache directory location." msgstr "" -#: includes/share.php:1507 includes/share.php:1616 +#: includes/share.php:1507 includes/share.php:1618 msgid "The `options` property w/ a `cache_max_age` key is not defined in this class." msgstr "" -#: includes/share.php:1531 +#: includes/share.php:1533 msgid "Unable to delete files. Rename failure on directory: `%1$s`." msgstr "" -#: includes/share.php:1548 includes/share.php:1676 includes/share.php:1749 +#: includes/share.php:1550 includes/share.php:1680 includes/share.php:1755 msgid "Unable to delete file: `%1$s`." msgstr "" -#: includes/share.php:1554 includes/share.php:1682 includes/share.php:1755 +#: includes/share.php:1556 includes/share.php:1686 includes/share.php:1761 msgid "Unable to delete dir: `%1$s`." msgstr "" -#: includes/share.php:1561 includes/share.php:1659 includes/share.php:1689 +#: includes/share.php:1563 includes/share.php:1663 includes/share.php:1693 msgid "Unable to delete files. Rename failure on tmp directory: `%1$s`." msgstr "" -#: includes/share.php:1741 includes/share.php:1762 +#: includes/share.php:1747 includes/share.php:1768 msgid "Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`." msgstr "" -#: includes/share.php:1767 +#: includes/share.php:1773 msgid "Unable to delete directory: `%1$s`." msgstr "" -#: includes/share.php:1799 +#: includes/share.php:1808 msgid "Unable to find the wp-config.php file." msgstr "" -#: includes/share.php:1809 +#: includes/share.php:1824 msgid "No writable tmp directory." msgstr "" -#: includes/share.php:1814 +#: includes/share.php:1829 msgid "Unable to obtain an exclusive lock." msgstr "" -#: includes/share.php:1864 +#: includes/share.php:1882 msgid "%1$s file" msgid_plural "%1$s files" msgstr[0] "" msgstr[1] "" -#: includes/share.php:1880 +#: includes/share.php:1898 msgid "%1$s directory" msgid_plural "%1$s directories" msgstr[0] "" msgstr[1] "" -#: includes/share.php:1896 +#: includes/share.php:1914 msgid "%1$s file/directory" msgid_plural "%1$s files/directories" msgstr[0] "" msgstr[1] "" -#: includes/share.php:1929 +#: includes/share.php:1947 msgid "Invalid hook." msgstr "" @@ -1142,7 +1142,7 @@ msgstr "" msgid "Quick Cache: detected a new version of itself. Recompiling w/ latest version... wiping the cache... all done :-)" msgstr "" -#. #-#-#-#-# quick-cache.pot (Quick Cache 141205) #-#-#-#-# +#. #-#-#-#-# quick-cache.pot (Quick Cache 141231) #-#-#-#-# #. Plugin Name of the plugin/theme #: quick-cache.inc.php:551 quick-cache.inc.php:567 msgid "Quick Cache" From cca62c8206c77be76da1541401e4c5ed11c29bcd Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Wed, 31 Dec 2014 17:36:39 -0500 Subject: [PATCH 8/8] Releasing Quick Cache v141231 --- quick-cache/includes/share.php | 2 +- quick-cache/quick-cache.php | 2 +- quick-cache/readme.txt | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index b067a8a..0009ee1 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -52,7 +52,7 @@ abstract class share // Shared between {@link advanced_cache} and {@link plugin} * * @var string Current version of the software. */ - public $version = '141229'; + public $version = '141231'; /** * Plugin slug; based on `__NAMESPACE__`. diff --git a/quick-cache/quick-cache.php b/quick-cache/quick-cache.php index 7f7c72a..508a57c 100644 --- a/quick-cache/quick-cache.php +++ b/quick-cache/quick-cache.php @@ -1,6 +1,6 @@