Skip to content

Commit

Permalink
fixes #31655 - don't delete the source files when generating thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Jun 6, 2018
1 parent 738dfab commit 1aae415
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/private/Preview/MP3.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {

$getID3 = new ID3Parser();
$tags = $getID3->analyze($absPath);
unlink($absPath);

$picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
$picture = $tags['id3v2']['PIC'][0]['data'];
Expand Down
7 changes: 3 additions & 4 deletions lib/private/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
//create imagick object from pdf
$pdfPreview = null;
try {
$pathInfo = pathinfo($absPath);
$pdfPreview = $pathInfo['dirname'] . '/' . $pathInfo['filename'] . '.pdf';
$pathInfo = \pathinfo($absPath);
$pdfPreview = $tmpDir . '/' . $pathInfo['filename'] . '.pdf';

$pdf = new \imagick($pdfPreview . '[0]');
$pdf->setImageFormat('jpg');
Expand All @@ -77,8 +77,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
$image = new \OC_Image();
$image->loadFromData($pdf);

unlink($absPath);
unlink($pdfPreview);
\unlink($pdfPreview);

if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
Expand Down
26 changes: 12 additions & 14 deletions tests/lib/Preview/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

namespace Test\Preview;

use OCP\Files\File;
use OCP\Files\Node;
use OCP\Preview\IProvider2;
use Test\Traits\UserTrait;

abstract class Provider extends \Test\TestCase {
use UserTrait;

/** @var Node */
/** @var File */
protected $imgPath;
/** @var int */
protected $width;
Expand All @@ -46,8 +47,6 @@ abstract class Provider extends \Test\TestCase {
protected $userId;
/** @var \OC\Files\View */
protected $rootView;
/** @var \OC\Files\Storage\Storage */
protected $storage;

protected function setUp() {
parent::setUp();
Expand All @@ -59,12 +58,7 @@ protected function setUp() {
$this->createUser($userId, $userId);
$this->loginAsUser($userId);

$this->storage = new \OC\Files\Storage\Temporary([]);
\OC\Files\Filesystem::mount($this->storage, [], '/' . $userId . '/');

$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/' . $userId);
$this->rootView->mkdir('/' . $userId . '/files');

$this->userId = $userId;
}
Expand All @@ -77,10 +71,10 @@ protected function tearDown() {

public static function dimensionsDataProvider() {
return [
[-rand(5, 100), -rand(5, 100)],
[rand(5, 100), rand(5, 100)],
[-rand(5, 100), rand(5, 100)],
[rand(5, 100), -rand(5, 100)],
[-\random_int(5, 100), -\random_int(5, 100)],
[\random_int(5, 100), \random_int(5, 100)],
[-\random_int(5, 100), \random_int(5, 100)],
[\random_int(5, 100), -\random_int(5, 100)],
];
}

Expand Down Expand Up @@ -119,14 +113,14 @@ public function testGetThumbnail($widthAdjustment, $heightAdjustment) {
* @param string $fileContent path to file to use for test
*
* @return Node
* @throws \Exception
* @throws \OCP\Files\NotFoundException
*/
protected function prepareTestFile($fileName, $fileContent) {
$imgData = file_get_contents($fileContent);
$imgPath = '/' . $this->userId . '/files/' . $fileName;
$this->rootView->file_put_contents($imgPath, $imgData);

$scanner = $this->storage->getScanner();
$scanner->scan('');
return \OC::$server->getUserFolder($this->userId)->get($fileName);
}

Expand All @@ -136,13 +130,17 @@ protected function prepareTestFile($fileName, $fileContent) {
* @param IProvider2 $provider
*
* @return bool|\OCP\IImage
* @throws \OCP\Files\NotPermittedException
*/
private function getPreview($provider) {
$preview = $provider->getThumbnail($this->imgPath, $this->maxWidth, $this->maxHeight, $this->scalingUp);

$this->assertNotFalse($preview);
$this->assertTrue($preview->valid());

// test that the file still exists
$this->assertNotNull($this->imgPath->getContent());

return $preview;
}

Expand Down

0 comments on commit 1aae415

Please sign in to comment.