Skip to content

Commit

Permalink
Merge branch 'release/141229'
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Dec 31, 2014
2 parents 283c524 + cca62c8 commit b21e939
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
44 changes: 31 additions & 13 deletions quick-cache/includes/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '141231';

/**
* Plugin slug; based on `__NAMESPACE__`.
Expand Down Expand Up @@ -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.

Expand All @@ -1531,7 +1533,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.

Expand All @@ -1555,7 +1557,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));
Expand Down Expand Up @@ -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?\/`.
Expand Down Expand Up @@ -1659,7 +1663,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.

Expand All @@ -1683,7 +1687,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));
Expand Down Expand Up @@ -1737,11 +1741,13 @@ 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));

/** @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.
{
Expand All @@ -1756,7 +1762,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));
Expand All @@ -1783,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.
Expand All @@ -1795,15 +1801,24 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE)
*/
public function cache_lock()
{
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));

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 = $this->apply_filters(__METHOD__.'_lock_type', '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));
Expand All @@ -1825,6 +1840,9 @@ public function cache_lock()
*/
public function cache_unlock(array $lock)
{
if($this->apply_filters(__CLASS__.'_disable_cache_locking', FALSE))
return;

if(!is_array($lock))
return; // Not possible.

Expand Down
34 changes: 17 additions & 17 deletions quick-cache/includes/translations/quick-cache.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -1142,7 +1142,7 @@ msgstr ""
msgid "<strong>Quick Cache:</strong> 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"
Expand Down
2 changes: 1 addition & 1 deletion quick-cache/quick-cache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
Version: 141205
Version: 141231
Text Domain: quick-cache
Plugin Name: Quick Cache
Network: true
Expand Down
11 changes: 9 additions & 2 deletions quick-cache/readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=== Quick Cache (Speed Without Compromise) ===

Stable tag: 141205
Stable tag: 141231
Requires at least: 3.7
Tested up to: 4.0.1
Tested up to: 4.1
Text Domain: quick-cache

License: GPLv2 or later
Expand Down Expand Up @@ -324,6 +324,13 @@ Requires PHP v5.3+. The latest version of Quick Cache is a complete rewrite (OOP

== Changelog ==

= v141231 =

- **Bug Fix**: Addressed another issue related to "Fatal Error: 'Unable to clear dir'" and tmp directories that don't get cleared by Quick Cache. This fix discards iteration references before renaming the tmp directories. Props @jaswsinc. See [#288](https://github.com/websharks/quick-cache/issues/288).
- **Bug Fix**: We have had a few reports of getMTime Stat failing when clearing the cache. This fix clears the Stat Cache before iteration when deleting files from the cache directory. Props @jaswsinc. See [#385](https://github.com/websharks/quick-cache/issues/385).
- **Enhancement**: Added a new filter (`quick_cache\\share_disable_cache_locking`) to allow disabling cache locking. Simply return boolean `TRUE` to this filter to disable cache locking. This may be useful for site owners who are experiencing issues with cache locking on web hosting platforms with filesystems that don't properly support locking. Note that this filter must be applied using an Advanced Cache Plugin (see **Dashboard → Quick Cache → Plugin Options → Theme/Plugin Developers**). See also [#387](https://github.com/websharks/quick-cache/issues/387).
- **Enhancement**: Added a new filter that allows forcing Semaphore cache locking on hosting platforms where `sem_get()` is available and would result in improved performance. Return `sem` to the `quick_cache\\share::cache_lock_lock_type` filter to force Semaphore cache locking, or `flock` to use the default method that uses `flock()`. Note that this filter must be applied using an Advanced Cache Plugin (see **Dashboard → Quick Cache → Plugin Options → Theme/Plugin Developers**). See also [#387](https://github.com/websharks/quick-cache/issues/387).

= v141205 =

- **Bug Fix**: Addressed another issue with "Fatal Error: 'Unable to clear dir'" messages by adding new blocking methods for cache lock and unlock, making it so that cache writes (including clearing, purging, wiping) all gain an exclusive lock on the cache directory while work is underway. Props @jaswsinc. See [#288](https://github.com/websharks/quick-cache/issues/288).
Expand Down

0 comments on commit b21e939

Please sign in to comment.