diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-03-26 23:08:08 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-03-26 23:08:08 +0100 |
commit | 746be98e0387ea138c4413fb89ad7e9ee87ce7aa (patch) | |
tree | 96decc89487fed61b0a111e4d630cf668c615c99 | |
parent | d082e37270f19269cd13098cb013c8543f4a1843 (diff) | |
parent | f890c3ffb1b7f7f1b744b37426993010e0c39138 (diff) | |
download | nextcloud-server-746be98e0387ea138c4413fb89ad7e9ee87ce7aa.tar.gz nextcloud-server-746be98e0387ea138c4413fb89ad7e9ee87ce7aa.zip |
Merge pull request #13654 from oparoz/tmpfile-with-extension
Keep the extension in temp files
-rw-r--r-- | lib/private/preview/office.php | 10 | ||||
-rw-r--r-- | lib/private/tempmanager.php | 3 | ||||
-rw-r--r-- | tests/lib/tempmanager.php | 12 |
3 files changed, 16 insertions, 9 deletions
diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index b97c29f50ba..54c0c26c079 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -45,12 +45,16 @@ abstract class Office extends Provider { shell_exec($exec); //create imagick object from pdf + $pdfPreview = null; try{ - $pdf = new \imagick($absPath . '.pdf' . '[0]'); + list( $dirname, , , $filename ) = array_values( pathinfo($absPath) ); + $pdfPreview = $dirname . '/' . $filename . '.pdf'; + + $pdf = new \imagick($pdfPreview . '[0]'); $pdf->setImageFormat('jpg'); } catch (\Exception $e) { unlink($absPath); - unlink($absPath . '.pdf'); + unlink($pdfPreview); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } @@ -59,7 +63,7 @@ abstract class Office extends Provider { $image->loadFromData($pdf); unlink($absPath); - unlink($absPath . '.pdf'); + unlink($pdfPreview); return $image->valid() ? $image : false; } diff --git a/lib/private/tempmanager.php b/lib/private/tempmanager.php index 33c3f1e9aef..197c0233142 100644 --- a/lib/private/tempmanager.php +++ b/lib/private/tempmanager.php @@ -55,6 +55,9 @@ class TempManager implements ITempManager { } protected function generatePath($postFix) { + if ($postFix) { + $postFix = '.' . ltrim($postFix, '.'); + } return $this->tmpBaseDir . '/oc_tmp_' . md5(time() . rand()) . $postFix; } diff --git a/tests/lib/tempmanager.php b/tests/lib/tempmanager.php index c030eef2c9e..427e260c3fb 100644 --- a/tests/lib/tempmanager.php +++ b/tests/lib/tempmanager.php @@ -51,7 +51,7 @@ class TempManager extends \Test\TestCase { public function testGetFile() { $manager = $this->getManager(); - $file = $manager->getTemporaryFile('.txt'); + $file = $manager->getTemporaryFile('txt'); $this->assertStringEndsWith('.txt', $file); $this->assertTrue(is_file($file)); $this->assertTrue(is_writable($file)); @@ -73,8 +73,8 @@ class TempManager extends \Test\TestCase { public function testCleanFiles() { $manager = $this->getManager(); - $file1 = $manager->getTemporaryFile('.txt'); - $file2 = $manager->getTemporaryFile('.txt'); + $file1 = $manager->getTemporaryFile('txt'); + $file2 = $manager->getTemporaryFile('txt'); $this->assertTrue(file_exists($file1)); $this->assertTrue(file_exists($file2)); @@ -105,8 +105,8 @@ class TempManager extends \Test\TestCase { public function testCleanOld() { $manager = $this->getManager(); - $oldFile = $manager->getTemporaryFile('.txt'); - $newFile = $manager->getTemporaryFile('.txt'); + $oldFile = $manager->getTemporaryFile('txt'); + $newFile = $manager->getTemporaryFile('txt'); $folder = $manager->getTemporaryFolder(); $nonOcFile = $this->baseDir . '/foo.txt'; file_put_contents($nonOcFile, 'bar'); @@ -135,7 +135,7 @@ class TempManager extends \Test\TestCase { $logger->expects($this->once()) ->method('warning') ->with($this->stringContains('Can not create a temporary file in directory')); - $this->assertFalse($manager->getTemporaryFile('.txt')); + $this->assertFalse($manager->getTemporaryFile('txt')); } public function testLogCantCreateFolder() { |