]> source.dussan.org Git - nextcloud-server.git/commitdiff
Change default mimetype detection for storage backends to only use filename
authorRobin Appelman <icewind@owncloud.com>
Wed, 20 Nov 2013 14:25:29 +0000 (15:25 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 20 Nov 2013 14:25:29 +0000 (15:25 +0100)
lib/private/files/storage/common.php
lib/private/files/storage/commontest.php
lib/private/files/storage/local.php
lib/private/files/storage/mappedlocal.php

index 3943d667c35715f368ef9646ae72286ede87c4ac..f99bbc9ae5e386f4015733ecfafc55c07220d60b 100644 (file)
@@ -142,7 +142,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
                        return false;
                } else {
                        $directoryHandle = $this->opendir($directory);
-                       if(is_resource($directoryHandle)) {
+                       if (is_resource($directoryHandle)) {
                                while (($contents = readdir($directoryHandle)) !== false) {
                                        if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
                                                $path = $directory . '/' . $contents;
@@ -165,27 +165,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
        }
 
        public function getMimeType($path) {
-               if (!$this->file_exists($path)) {
-                       return false;
-               }
                if ($this->is_dir($path)) {
                        return 'httpd/unix-directory';
-               }
-               $source = $this->fopen($path, 'r');
-               if (!$source) {
-                       return false;
-               }
-               $head = fread($source, 8192); //8kb should suffice to determine a mimetype
-               if ($pos = strrpos($path, '.')) {
-                       $extension = substr($path, $pos);
+               } elseif ($this->file_exists($path)) {
+                       return \OC_Helper::getFileNameMimeType($path);
                } else {
-                       $extension = '';
+                       return false;
                }
-               $tmpFile = \OC_Helper::tmpFile($extension);
-               file_put_contents($tmpFile, $head);
-               $mime = \OC_Helper::getMimeType($tmpFile);
-               unlink($tmpFile);
-               return $mime;
        }
 
        public function hash($type, $path, $raw = false) {
@@ -227,7 +213,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
 
        private function addLocalFolder($path, $target) {
                $dh = $this->opendir($path);
-               if(is_resource($dh)) {
+               if (is_resource($dh)) {
                        while (($file = readdir($dh)) !== false) {
                                if ($file !== '.' and $file !== '..') {
                                        if ($this->is_dir($path . '/' . $file)) {
@@ -298,7 +284,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
                return $this->watcher;
        }
 
-       public function getStorageCache(){
+       public function getStorageCache() {
                if (!isset($this->storageCache)) {
                        $this->storageCache = new \OC\Files\Cache\Storage($this);
                }
index c3f1eb31955a5f516745063869fc0e42331f1f2c..2394b14a82fa494ce3daa0ba60c40154fe0435e5 100644 (file)
@@ -54,7 +54,7 @@ class CommonTest extends \OC\Files\Storage\Common{
                return $this->storage->stat($path);
        }
        public function filetype($path) {
-               return $this->storage->filetype($path);
+               return @$this->storage->filetype($path);
        }
        public function isReadable($path) {
                return $this->storage->isReadable($path);
index 5209fabc30ad0ac6a4adfa665220e7ee61d9bd73..02e8df4af4e944da1e96466bd1a26bb19c8cf214 100644 (file)
@@ -203,14 +203,6 @@ if (\OC_Util::runningOnWindows()) {
                        return $return;
                }
 
-               public function getMimeType($path) {
-                       if ($this->isReadable($path)) {
-                               return \OC_Helper::getMimeType($this->datadir . $path);
-                       } else {
-                               return false;
-                       }
-               }
-
                private function delTree($dir) {
                        $dirRelative = $dir;
                        $dir = $this->datadir . $dir;
index ba5ac4191c5b9b1fc595fb472c2c17125bd0a2d4..6c37d445867795bc5a37f857860ba9bcc66ee28f 100644 (file)
@@ -210,14 +210,6 @@ class MappedLocal extends \OC\Files\Storage\Common{
                return $return;
        }
 
-       public function getMimeType($path) {
-               if($this->isReadable($path)) {
-                       return \OC_Helper::getMimeType($this->buildPath($path));
-               }else{
-                       return false;
-               }
-       }
-
        private function delTree($dir, $isLogicPath=true) {
                $dirRelative=$dir;
                if ($isLogicPath) {