From 19f2ac94b2fb2c2239cda653dff02c1fd1f35262 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 12 Mar 2010 10:11:25 -0500 Subject: [PATCH] Catch (and ignore) exceptinos from VFS when deleting ansel's image cache. We don't care if the file doesn't exist when deleting it...and it saves having to stat the file before deleting it. --- ansel/lib/Image.php | 57 ++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index 0775350a4..2e57a7d19 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -753,40 +753,43 @@ class Ansel_Image Implements Iterator */ public function deleteCache($view = 'all') { - /* Delete cached screen image. */ - if ($view == 'all' || $view == 'screen') { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('screen'), - $this->getVFSName('screen')); - } + /* Catch exceptions from VFS */ + try { + /* Delete cached screen image. (We don't care if the file is not found) */ + if ($view == 'all' || $view == 'screen') { + $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('screen'), + $this->getVFSName('screen')); + } - /* Delete cached thumbnail. */ - if ($view == 'all' || $view == 'thumb') { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('thumb'), - $this->getVFSName('thumb')); - } + /* Delete cached thumbnail. */ + if ($view == 'all' || $view == 'thumb') { + $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('thumb'), + $this->getVFSName('thumb')); + } - /* Delete cached mini image. */ - if ($view == 'all' || $view == 'mini') { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('mini'), - $this->getVFSName('mini')); - } + /* Delete cached mini image. */ + if ($view == 'all' || $view == 'mini') { + $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('mini'), + $this->getVFSName('mini')); + } - if ($view == 'all' || $view == 'prettythumb') { + if ($view == 'all' || $view == 'prettythumb') { - /* No need to try to delete a hash we already removed */ - $deleted = array(); + /* No need to try to delete a hash we already removed */ + $deleted = array(); - /* Need to generate hashes for each possible style */ - $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); - foreach ($styles as $style) { - $hash = md5($style['thumbstyle'] . '.' . $style['background']); - if (empty($deleted[$hash])) { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath($hash), - $this->getVFSName($hash)); - $deleted[$hash] = true; + /* Need to generate hashes for each possible style */ + $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); + foreach ($styles as $style) { + $hash = md5($style['thumbstyle'] . '.' . $style['background']); + if (empty($deleted[$hash])) { + $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath($hash), + $this->getVFSName($hash)); + $deleted[$hash] = true; + } } } - } + } catch (VFS_Exception $e) {} } /** -- 2.11.0