From 045d57189c1fb4e8775603cd39927557e3eddfd9 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 9 Aug 2013 21:34:51 +0200 Subject: make sure temporary folders are cleaned up --- lib/plugins/extension/helper/extension.php | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'lib/plugins/extension') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index 8438253f9..dc570aa0d 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -23,6 +23,20 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** @var helper_plugin_extension_repository $repository */ private $repository = null; + /** @var array list of temporary directories */ + private $temporary = array(); + + /** + * Destructor + * + * deletes any dangling temporary directories + */ + public function __destruct() { + foreach($this->temporary as $dir){ + $this->dir_delete($dir); + } + } + /** * @return bool false, this component is not a singleton */ @@ -697,6 +711,20 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { } } + /** + * Returns a temporary directory + * + * The directory is registered for cleanup when the class is destroyed + * + * @return bool|string + */ + protected function mkTmpDir(){ + $dir = io_mktmpdir(); + if(!$dir) return false; + $this->temporary[] = $dir; + return $dir; + } + /** * Download an archive to a protected path * @@ -713,7 +741,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $file = $matches[0]; // create tmp directory for download - if(!($tmp = io_mktmpdir())) { + if(!($tmp = $this->mkTmpDir())) { throw new Exception($this->getLang('error_dircreate')); } @@ -736,7 +764,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { public function installArchive($file, $overwrite=false, $base = '') { // create tmp directory for decompression - if(!($tmp = io_mktmpdir())) { + if(!($tmp = $this->mkTmpDir())) { throw new Exception($this->getLang('error_dircreate')); } -- cgit v1.2.3