diff --git a/composer.json b/composer.json index 6f4b288..7fb6cfc 100644 --- a/composer.json +++ b/composer.json @@ -1,29 +1,32 @@ { - "name": "keboola/php-temp", - "description": "Temp service - handles application's temporary files", - "license": "MIT", - "keywords": ["filesystem", "temp"], - "authors": [ - { - "name": "Miro Cillik", - "email": "miro@keboola.cz" - }, - { - "name": "Ondrej Vana", - "email": "kachna@keboola.cz" - } - ], - "require": { - "symfony/filesystem": ">2.1.0", - "php": ">=5.3.3" + "name": "keboola/php-temp", + "description": "Temp service - handles application's temporary files", + "license": "MIT", + "keywords": [ + "filesystem", + "temp" + ], + "authors": [ + { + "name": "Miro Cillik", + "email": "miro@keboola.cz" }, - "require-dev": { - "phpunit/phpunit": "^5.2", - "codeclimate/php-test-reporter": "dev-master" - }, - "autoload": { - "psr-0": { - "Keboola\\Temp": "src/" - } - } + { + "name": "Ondrej Vana", + "email": "kachna@keboola.cz" + } + ], + "require": { + "symfony/filesystem": ">2.1.0", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "^5.2", + "codeclimate/php-test-reporter": "dev-master" + }, + "autoload": { + "psr-0": { + "Keboola\\Temp": "src/" + } + } } diff --git a/src/Keboola/Temp/Temp.php b/src/Keboola/Temp/Temp.php index 04294c5..d76ff20 100644 --- a/src/Keboola/Temp/Temp.php +++ b/src/Keboola/Temp/Temp.php @@ -148,17 +148,23 @@ function __destruct() { $preserveRunFolder = $this->preserveRunFolder; - foreach ($this->files as $file) { - if ($file['preserve']) { - $preserveRunFolder = true; + try { + foreach ($this->files as $file) { + if ($file['preserve']) { + $preserveRunFolder = true; + } + if (file_exists($file['file']) && is_file($file['file']) && !$file['preserve']) { + $this->filesystem->remove($file['file']->getPathname()); + } } - if (file_exists($file['file']) && is_file($file['file']) && !$file['preserve']) { - $this->filesystem->remove($file['file']->getPathname()); - } - } - if (!$preserveRunFolder && is_dir($this->getTmpPath())) { - $this->filesystem->remove($this->getTmpPath()); + if (!$preserveRunFolder && is_dir($this->getTmpPath())) { + $this->filesystem->remove($this->getTmpPath()); + } + } catch (\Exception $e) { + // Graceful destructor, does not throw any errors. + // Fixes issues when deleting files on a server that is just shutting down. + // https://github.com/keboola/docker-bundle/issues/215 } } }