Skip to content

Commit

Permalink
Merge pull request #6 from keboola/graceful-destructor
Browse files Browse the repository at this point in the history
fixes #6
  • Loading branch information
ondrejhlavacek authored Nov 13, 2017
2 parents ffe345e + 62c82ad commit 061008a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
55 changes: 29 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
},
{
"name": "Ondrej Vana",
"email": "[email protected]"
}
],
"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": "[email protected]"
},
"require-dev": {
"phpunit/phpunit": "^5.2",
"codeclimate/php-test-reporter": "dev-master"
},
"autoload": {
"psr-0": {
"Keboola\\Temp": "src/"
}
}
{
"name": "Ondrej Vana",
"email": "[email protected]"
}
],
"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/"
}
}
}
24 changes: 15 additions & 9 deletions src/Keboola/Temp/Temp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 061008a

Please sign in to comment.