[Pkg-owncloud-commits] [owncloud] 217/239: Redetect mime type whenever extension is renamed

David Prévot taffit at moszumanska.debian.org
Fri Nov 29 01:32:40 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 43b1cf798839888e9e7266d80f55f6ce6f74d852
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Wed Nov 27 18:48:24 2013 +0100

    Redetect mime type whenever extension is renamed
---
 lib/private/files/cache/updater.php | 6 ++++++
 tests/lib/files/cache/updater.php   | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php
index d45c5e1..9ef147a 100644
--- a/lib/private/files/cache/updater.php
+++ b/lib/private/files/cache/updater.php
@@ -86,6 +86,12 @@ class Updater {
 			if ($storageFrom === $storageTo) {
 				$cache = $storageFrom->getCache($internalFrom);
 				$cache->move($internalFrom, $internalTo);
+				if (pathinfo($internalFrom, PATHINFO_EXTENSION) !== pathinfo($internalTo, PATHINFO_EXTENSION)) {
+					// redetect mime type change
+					$mimeType = $storageTo->getMimeType($internalTo);
+					$fileId = $storageTo->getCache()->getId($internalTo);
+					$storageTo->getCache()->update($fileId, array('mimetype' => $mimeType));
+				}
 				$cache->correctFolderSize($internalFrom);
 				$cache->correctFolderSize($internalTo);
 				self::correctFolder($from, time());
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index e3d3aae..91e384e 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -202,6 +202,14 @@ class Updater extends \PHPUnit_Framework_TestCase {
 		$this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
 	}
 
+	public function testRenameExtension() {
+		$fooCachedData = $this->cache->get('foo.txt');
+		$this->assertEquals('text/plain', $fooCachedData['mimetype']);
+		Filesystem::rename('foo.txt', 'foo.abcd');
+		$fooCachedData = $this->cache->get('foo.abcd');
+		$this->assertEquals('application/octet-stream', $fooCachedData['mimetype']);
+	}
+
 	public function testRenameWithMountPoints() {
 		$storage2 = new \OC\Files\Storage\Temporary(array());
 		$cache2 = $storage2->getCache();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list