Redetect mime type whenever extension is renamed

This commit is contained in:
Vincent Petry 2013-11-27 18:48:24 +01:00
parent 40231c08cf
commit 43b1cf7988
2 changed files with 14 additions and 0 deletions

View File

@ -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());

View File

@ -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();