diff --git a/src/Keboola/Temp/Temp.php b/src/Keboola/Temp/Temp.php index d76ff20..0f01063 100644 --- a/src/Keboola/Temp/Temp.php +++ b/src/Keboola/Temp/Temp.php @@ -22,11 +22,6 @@ class Temp */ protected $files = array(); - /** - * @var Bool - */ - protected $preserveRunFolder = false; - /** * * If temp folder needs to be deterministic, you can use ID as the last part of folder name @@ -50,14 +45,6 @@ public function initRunFolder() } } - /** - * @param bool $value - */ - public function setPreserveRunFolder($value) - { - $this->preserveRunFolder = $value; - } - /** * Get path to temp directory * @@ -87,11 +74,10 @@ public function getTmpFolder() * Create empty file in TMP directory * * @param string $suffix filename suffix - * @param bool $preserve * @throws \Exception * @return \SplFileInfo */ - public function createTmpFile($suffix = null, $preserve = false) + public function createTmpFile($suffix = null) { $file = uniqid(); @@ -99,18 +85,17 @@ public function createTmpFile($suffix = null, $preserve = false) $file .= '-' . $suffix; } - return $this->createFile($file, $preserve); + return $this->createFile($file); } /** * Creates named temporary file * * @param $fileName - * @param bool $preserve * @return \SplFileInfo * @throws \Exception */ - public function createFile($fileName, $preserve = false) + public function createFile($fileName) { $this->initRunFolder(); @@ -124,8 +109,7 @@ public function createFile($fileName, $preserve = false) $this->filesystem->touch($pathName); $this->files[] = array( - 'file' => $fileInfo, - 'preserve' => $preserve + 'file' => $fileInfo ); $this->filesystem->chmod($pathName, 0600); @@ -146,21 +130,13 @@ public function setId($id) { */ function __destruct() { - $preserveRunFolder = $this->preserveRunFolder; - try { foreach ($this->files as $file) { - if ($file['preserve']) { - $preserveRunFolder = true; - } - if (file_exists($file['file']) && is_file($file['file']) && !$file['preserve']) { + if (file_exists($file['file']) && is_file($file['file'])) { $this->filesystem->remove($file['file']->getPathname()); } } - - if (!$preserveRunFolder && is_dir($this->getTmpPath())) { - $this->filesystem->remove($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. diff --git a/tests/Keboola/Temp/TempTest.php b/tests/Keboola/Temp/TempTest.php index 029731a..c53acd2 100644 --- a/tests/Keboola/Temp/TempTest.php +++ b/tests/Keboola/Temp/TempTest.php @@ -92,15 +92,4 @@ public function testCleanupForeignFile() unset($temp); self::assertFileNotExists($dir); } - - public function testCleanupFilePreserve() - { - $temp = new Temp(); - $file = $temp->createFile('file', true); - - unset($temp); - self::assertFileExists($file->getPathname()); - unlink($file->getPathname()); - rmdir(dirname($file->getPathname())); - } }