From a18c0983d5db32e98461404888200118f83011d7 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 18 Dec 2015 11:25:33 +0100 Subject: [PATCH] Use TempManager instead of tmpFile --- .../files/objectstore/objectstorestorage.php | 2 +- lib/private/files/storage/localtempfiletrait.php | 2 +- lib/private/files/type/detection.php | 2 +- lib/private/files/view.php | 2 +- lib/private/helper.php | 13 ------------- lib/private/installer.php | 2 +- lib/private/preview/movie.php | 4 ++-- tests/lib/files/filesystem.php | 2 +- tests/lib/installer.php | 6 +++--- tests/lib/streamwrappers.php | 4 ++-- 10 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/private/files/objectstore/objectstorestorage.php b/lib/private/files/objectstore/objectstorestorage.php index a053ea6d6d2..b34a6bdfb84 100644 --- a/lib/private/files/objectstore/objectstorestorage.php +++ b/lib/private/files/objectstore/objectstorestorage.php @@ -274,7 +274,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { } else { $ext = ''; } - $tmpFile = \OC_Helper::tmpFile($ext); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'r'); diff --git a/lib/private/files/storage/localtempfiletrait.php b/lib/private/files/storage/localtempfiletrait.php index 84331f49b19..8875c2c4493 100644 --- a/lib/private/files/storage/localtempfiletrait.php +++ b/lib/private/files/storage/localtempfiletrait.php @@ -70,7 +70,7 @@ trait LocalTempFileTrait { } else { $extension = ''; } - $tmpFile = \OC_Helper::tmpFile($extension); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension); $target = fopen($tmpFile, 'w'); \OC_Helper::streamCopy($source, $target); fclose($target); diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index c102e739e04..0e2bab39e5b 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -238,7 +238,7 @@ class Detection implements IMimeTypeDetector { $finfo = finfo_open(FILEINFO_MIME); return finfo_buffer($finfo, $data); } else { - $tmpFile = \OC_Helper::tmpFile(); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); $fh = fopen($tmpFile, 'wb'); fwrite($fh, $data, 8024); fclose($fh); diff --git a/lib/private/files/view.php b/lib/private/files/view.php index b8b1b8a50d6..fcea4828c49 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -912,7 +912,7 @@ class View { $source = $this->fopen($path, 'r'); if ($source) { $extension = pathinfo($path, PATHINFO_EXTENSION); - $tmpFile = \OC_Helper::tmpFile($extension); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension); file_put_contents($tmpFile, $source); return $tmpFile; } else { diff --git a/lib/private/helper.php b/lib/private/helper.php index 556286f3519..08ddf2b0522 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -456,19 +456,6 @@ class OC_Helper { return array($count, $result); } - /** - * create a temporary file with an unique filename - * - * @param string $postfix - * @return string - * @deprecated Use the TempManager instead - * - * temporary files are automatically cleaned up after the script is finished - */ - public static function tmpFile($postfix = '') { - return \OC::$server->getTempManager()->getTemporaryFile($postfix); - } - /** * Adds a suffix to the name in case the file exists * diff --git a/lib/private/installer.php b/lib/private/installer.php index c188f15718a..e1447db0db5 100644 --- a/lib/private/installer.php +++ b/lib/private/installer.php @@ -264,7 +264,7 @@ class OC_Installer{ //download the file if necessary if($data['source']=='http') { $pathInfo = pathinfo($data['href']); - $path=OC_Helper::tmpFile('.' . $pathInfo['extension']); + $path = \OC::$server->getTempManager()->getTemporaryFile('.' . $pathInfo['extension']); if(!isset($data['href'])) { throw new \Exception($l->t("No href specified when installing app from http")); } diff --git a/lib/private/preview/movie.php b/lib/private/preview/movie.php index f71eaaf3eb2..2c2e6d09399 100644 --- a/lib/private/preview/movie.php +++ b/lib/private/preview/movie.php @@ -46,7 +46,7 @@ class Movie extends Provider { if ($useFileDirectly) { $absPath = $fileview->getLocalFile($path); } else { - $absPath = \OC_Helper::tmpFile(); + $absPath = \OC::$server->getTempManager()->getTemporaryFile(); $handle = $fileview->fopen($path, 'rb'); @@ -79,7 +79,7 @@ class Movie extends Provider { * @return bool|\OCP\IImage */ private function generateThumbNail($maxX, $maxY, $absPath, $second) { - $tmpPath = \OC_Helper::tmpFile(); + $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); if (self::$avconvBinary) { $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 328ba5f4488..db1f22f894a 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -302,7 +302,7 @@ class Filesystem extends \Test\TestCase { \OC\Files\Filesystem::mkdir('/bar'); // \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo'); - $tmpFile = \OC_Helper::tmpFile(); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); file_put_contents($tmpFile, 'foo'); $fh = fopen($tmpFile, 'r'); // \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh); diff --git a/tests/lib/installer.php b/tests/lib/installer.php index c3c2f8a275e..cfad4d7f0de 100644 --- a/tests/lib/installer.php +++ b/tests/lib/installer.php @@ -32,7 +32,7 @@ class Test_Installer extends \Test\TestCase { $pathOfTestApp .= '/../data/'; $pathOfTestApp .= 'testapp.zip'; - $tmp = OC_Helper::tmpFile('.zip'); + $tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip'); OC_Helper::copyr($pathOfTestApp, $tmp); $data = array( @@ -51,7 +51,7 @@ class Test_Installer extends \Test\TestCase { $pathOfOldTestApp .= '/../data/'; $pathOfOldTestApp .= 'testapp.zip'; - $oldTmp = OC_Helper::tmpFile('.zip'); + $oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip'); OC_Helper::copyr($pathOfOldTestApp, $oldTmp); $oldData = array( @@ -63,7 +63,7 @@ class Test_Installer extends \Test\TestCase { $pathOfNewTestApp .= '/../data/'; $pathOfNewTestApp .= 'testapp2.zip'; - $newTmp = OC_Helper::tmpFile('.zip'); + $newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip'); OC_Helper::copyr($pathOfNewTestApp, $newTmp); $newData = array( diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index 9b097535280..7175683a60b 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -55,7 +55,7 @@ class Test_StreamWrappers extends \Test\TestCase { public function testCloseStream() { //ensure all basic stream stuff works $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt'; - $tmpFile = OC_Helper::TmpFile('.txt'); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt'); $file = 'close://' . $tmpFile; $this->assertTrue(file_exists($file)); file_put_contents($file, file_get_contents($sourceFile)); @@ -65,7 +65,7 @@ class Test_StreamWrappers extends \Test\TestCase { $this->assertFalse(file_exists($file)); //test callback - $tmpFile = OC_Helper::TmpFile('.txt'); + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt'); $file = 'close://' . $tmpFile; $actual = false; $callback = function($path) use (&$actual) { $actual = $path; }; -- 2.39.5