mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1497 from hiromi2424/fix-unlink-windows
Fix unlink() for CacheEngine::clear() failed on windows. Refs #3930
This commit is contained in:
commit
f63aa922f6
1 changed files with 14 additions and 4 deletions
|
@ -223,6 +223,8 @@ class FileEngine extends CacheEngine {
|
||||||
if (!$this->_init) {
|
if (!$this->_init) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$this->_File = null;
|
||||||
|
|
||||||
$threshold = $now = false;
|
$threshold = $now = false;
|
||||||
if ($check) {
|
if ($check) {
|
||||||
$now = time();
|
$now = time();
|
||||||
|
@ -233,11 +235,17 @@ class FileEngine extends CacheEngine {
|
||||||
|
|
||||||
$directory = new RecursiveDirectoryIterator($this->settings['path']);
|
$directory = new RecursiveDirectoryIterator($this->settings['path']);
|
||||||
$contents = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
|
$contents = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
|
$cleared = array();
|
||||||
foreach ($contents as $path) {
|
foreach ($contents as $path) {
|
||||||
if ($path->isFile()) {
|
if ($path->isFile()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->_clearDirectory($path->getRealPath() . DS, $now, $threshold);
|
|
||||||
|
$path = $path->getRealPath() . DS;
|
||||||
|
if (!in_array($path, $cleared)) {
|
||||||
|
$this->_clearDirectory($path, $now, $threshold);
|
||||||
|
$cleared[] = $path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +271,7 @@ class FileEngine extends CacheEngine {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$filePath = $path . $entry;
|
$filePath = $path . $entry;
|
||||||
if (is_dir($filePath)) {
|
if (!file_exists($filePath) || is_dir($filePath)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$file = new SplFileObject($path . $entry, 'r');
|
$file = new SplFileObject($path . $entry, 'r');
|
||||||
|
@ -281,7 +289,9 @@ class FileEngine extends CacheEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($file->isFile()) {
|
if ($file->isFile()) {
|
||||||
unlink($file->getRealPath());
|
$_path = $file->getRealPath();
|
||||||
|
$file = null;
|
||||||
|
unlink($_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,6 +398,7 @@ class FileEngine extends CacheEngine {
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
public function clearGroup($group) {
|
public function clearGroup($group) {
|
||||||
|
$this->_File = null;
|
||||||
$directoryIterator = new RecursiveDirectoryIterator($this->settings['path']);
|
$directoryIterator = new RecursiveDirectoryIterator($this->settings['path']);
|
||||||
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
|
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
foreach ($contents as $object) {
|
foreach ($contents as $object) {
|
||||||
|
@ -397,7 +408,6 @@ class FileEngine extends CacheEngine {
|
||||||
unlink($object->getPathName());
|
unlink($object->getPathName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->_File = null;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue