Skip to content

Commit

Permalink
Merge pull request #12 from koriym/spike
Browse files Browse the repository at this point in the history
Clear tmp directory [again]
  • Loading branch information
koriym authored Mar 24, 2017
2 parents 1456276 + 400c7ae commit 57c1dfc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/AppMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function __construct($name, $context = 'app', $appDir = null)
throw new NotWritableException($this->tmpDir);
}
$this->logDir = $this->appDir . '/var/log';
$isDevelop = strpos($context, 'prod') === false;
if ($isDevelop) {
$this->clearTmpDirectory($this->tmpDir);
}
}

/**
Expand All @@ -42,4 +46,27 @@ public function getResourceListGenerator()

return $resourceListGenerator;
}

/**
* @param string $dir
*/
private function clearTmpDirectory($dir)
{
/**
* A flag for clear once because called many times during the unit testing
*/
static $done = false;

if ($done) {
return;
}
$unlink = function ($path) use (&$unlink) {
foreach (glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*') as $file) {
is_dir($file) ? $unlink($file) : unlink($file);
@rmdir($file);
}
};
$unlink($dir);
$done = true;
}
}

0 comments on commit 57c1dfc

Please sign in to comment.