Merge pull request #8878 from nextcloud/remove_tmpfile

Remove deprecated tmpFile/tmpFolder
This commit is contained in:
Roeland Jago Douma 2018-03-19 12:29:08 +01:00 committed by GitHub
commit 9834f33d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 17 additions and 42 deletions

View File

@ -410,7 +410,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
} }
case 'w': case 'w':
case 'wb': case 'wb':
$tmpFile = \OCP\Files::tmpFile(); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
$handle = fopen($tmpFile, 'w'); $handle = fopen($tmpFile, 'w');
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
@ -431,7 +431,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
} else { } else {
$ext = ''; $ext = '';
} }
$tmpFile = \OCP\Files::tmpFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
if ($this->file_exists($path)) { if ($this->file_exists($path)) {
$source = $this->readObject($path); $source = $this->readObject($path);
file_put_contents($tmpFile, $source); file_put_contents($tmpFile, $source);

View File

@ -128,7 +128,7 @@ class FTP extends StreamWrapper{
} else { } else {
$ext=''; $ext='';
} }
$tmpFile=\OCP\Files::tmpFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
if ($this->file_exists($path)) { if ($this->file_exists($path)) {
$this->getFile($path, $tmpFile); $this->getFile($path, $tmpFile);
} }

View File

@ -353,7 +353,7 @@ class SMB extends Common implements INotifyStorage {
if (!$this->isCreatable(dirname($path))) { if (!$this->isCreatable(dirname($path))) {
return false; return false;
} }
$tmpFile = \OCP\Files::tmpFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
} }
$source = fopen($tmpFile, $mode); $source = fopen($tmpFile, $mode);
$share = $this->share; $share = $this->share;

View File

@ -428,7 +428,7 @@ class Swift extends \OC\Files\Storage\Common {
} else { } else {
$ext = ''; $ext = '';
} }
$tmpFile = \OCP\Files::tmpFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
// Fetch existing file if required // Fetch existing file if required
if ($mode[0] !== 'w' && $this->file_exists($path)) { if ($mode[0] !== 'w' && $this->file_exists($path)) {
if ($mode[0] === 'x') { if ($mode[0] === 'x') {

View File

@ -139,7 +139,7 @@ class TAR extends Archive {
*/ */
public function rename($source, $dest) { public function rename($source, $dest) {
//no proper way to delete, rename entire archive, rename file and remake archive //no proper way to delete, rename entire archive, rename file and remake archive
$tmp = \OCP\Files::tmpFolder(); $tmp = \OC::$server->getTempManager()->getTemporaryFolder();
$this->tar->extract($tmp); $this->tar->extract($tmp);
rename($tmp . $source, $tmp . $dest); rename($tmp . $source, $tmp . $dest);
$this->tar = null; $this->tar = null;
@ -258,7 +258,7 @@ class TAR extends Archive {
* @return bool * @return bool
*/ */
public function extractFile($path, $dest) { public function extractFile($path, $dest) {
$tmp = \OCP\Files::tmpFolder(); $tmp = \OC::$server->getTempManager()->getTemporaryFolder();
if (!$this->fileExists($path)) { if (!$this->fileExists($path)) {
return false; return false;
} }
@ -323,7 +323,7 @@ class TAR extends Archive {
$this->fileList = false; $this->fileList = false;
$this->cachedHeaders = false; $this->cachedHeaders = false;
//no proper way to delete, extract entire archive, delete file and remake archive //no proper way to delete, extract entire archive, delete file and remake archive
$tmp = \OCP\Files::tmpFolder(); $tmp = \OC::$server->getTempManager()->getTemporaryFolder();
$this->tar->extract($tmp); $this->tar->extract($tmp);
\OCP\Files::rmdirr($tmp . $path); \OCP\Files::rmdirr($tmp . $path);
$this->tar = null; $this->tar = null;
@ -346,7 +346,7 @@ class TAR extends Archive {
} else { } else {
$ext = ''; $ext = '';
} }
$tmpFile = \OCP\Files::tmpFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
if ($this->fileExists($path)) { if ($this->fileExists($path)) {
$this->extractFile($path, $tmpFile); $this->extractFile($path, $tmpFile);
} elseif ($mode == 'r' or $mode == 'rb') { } elseif ($mode == 'r' or $mode == 'rb') {

View File

@ -198,7 +198,7 @@ class ZIP extends Archive{
}else{ }else{
$ext=''; $ext='';
} }
$tmpFile=\OCP\Files::tmpFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
if($this->fileExists($path)) { if($this->fileExists($path)) {
$this->extractFile($path, $tmpFile); $this->extractFile($path, $tmpFile);
} }

View File

@ -206,7 +206,7 @@ abstract class Flysystem extends Common {
if (!$this->isCreatable(dirname($path))) { if (!$this->isCreatable(dirname($path))) {
return false; return false;
} }
$tmpFile = \OCP\Files::tmpFile(); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
} }
$source = fopen($tmpFile, $mode); $source = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath) { return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath) {

View File

@ -88,31 +88,6 @@ class Files {
return $count; return $count;
} }
/**
* Create a temporary file with an unique filename
* @param string $postfix
* @return string
*
* temporary files are automatically cleaned up after the script is finished
* @deprecated 8.1.0 use getTemporaryFile() of \OCP\ITempManager - \OC::$server->getTempManager()
* @since 5.0.0
*/
public static function tmpFile( $postfix='' ) {
return \OC::$server->getTempManager()->getTemporaryFile($postfix);
}
/**
* Create a temporary folder with an unique filename
* @return string
*
* temporary files are automatically cleaned up after the script is finished
* @deprecated 8.1.0 use getTemporaryFolder() of \OCP\ITempManager - \OC::$server->getTempManager()
* @since 5.0.0
*/
public static function tmpFolder() {
return \OC::$server->getTempManager()->getTemporaryFolder();
}
/** /**
* Adds a suffix to the name in case the file exists * Adds a suffix to the name in case the file exists
* @param string $path * @param string $path

View File

@ -18,6 +18,6 @@ class TARTest extends TestBase {
} }
protected function getNew() { protected function getNew() {
return new TAR(\OCP\Files::tmpFile('.tar.gz')); return new TAR(\OC::$server->getTempManager()->getTemporaryFile('.tar.gz'));
} }
} }

View File

@ -58,7 +58,7 @@ abstract class TestBase extends \Test\TestCase {
$textFile=$dir.'/lorem.txt'; $textFile=$dir.'/lorem.txt';
$this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt')); $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt'));
$tmpFile=\OCP\Files::tmpFile('.txt'); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
$this->instance->extractFile('lorem.txt', $tmpFile); $this->instance->extractFile('lorem.txt', $tmpFile);
$this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile)); $this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile));
} }
@ -112,7 +112,7 @@ abstract class TestBase extends \Test\TestCase {
public function testExtract() { public function testExtract() {
$dir=\OC::$SERVERROOT.'/tests/data'; $dir=\OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getExisting(); $this->instance=$this->getExisting();
$tmpDir=\OCP\Files::tmpFolder(); $tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
$this->instance->extract($tmpDir); $this->instance->extract($tmpDir);
$this->assertEquals(true, file_exists($tmpDir.'lorem.txt')); $this->assertEquals(true, file_exists($tmpDir.'lorem.txt'));
$this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt')); $this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt'));

View File

@ -18,6 +18,6 @@ class ZIPTest extends TestBase {
} }
protected function getNew() { protected function getNew() {
return new ZIP(\OCP\Files::tmpFile('.zip')); return new ZIP(\OC::$server->getTempManager()->getTemporaryFile('.zip'));
} }
} }

View File

@ -332,13 +332,13 @@ class UtilTest extends \Test\TestCase {
} }
public function testCheckDataDirectoryValidity() { public function testCheckDataDirectoryValidity() {
$dataDir = \OCP\Files::tmpFolder(); $dataDir = \OC::$server->getTempManager()->getTemporaryFolder();
touch($dataDir . '/.ocdata'); touch($dataDir . '/.ocdata');
$errors = \OC_Util::checkDataDirectoryValidity($dataDir); $errors = \OC_Util::checkDataDirectoryValidity($dataDir);
$this->assertEmpty($errors); $this->assertEmpty($errors);
\OCP\Files::rmdirr($dataDir); \OCP\Files::rmdirr($dataDir);
$dataDir = \OCP\Files::tmpFolder(); $dataDir = \OC::$server->getTempManager()->getTemporaryFolder();
// no touch // no touch
$errors = \OC_Util::checkDataDirectoryValidity($dataDir); $errors = \OC_Util::checkDataDirectoryValidity($dataDir);
$this->assertNotEmpty($errors); $this->assertNotEmpty($errors);