diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-30 22:11:19 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-30 22:11:19 +0100 |
commit | 261cd87efa5623b51bbfa466f94d243bb7b49336 (patch) | |
tree | 25dd1d72e0a1e7563dc4bb6deabc937afd7946ec /lib/private/files | |
parent | 0e92a4896df11d6fd3ee4ed73dfa1cb121d66895 (diff) | |
parent | c1730d241c52b5e5c1719b6086d05cb30783e665 (diff) | |
download | nextcloud-server-261cd87efa5623b51bbfa466f94d243bb7b49336.tar.gz nextcloud-server-261cd87efa5623b51bbfa466f94d243bb7b49336.zip |
Merge branch 'master' into home-storage
Diffstat (limited to 'lib/private/files')
-rw-r--r-- | lib/private/files/cache/cache.php | 4 | ||||
-rw-r--r-- | lib/private/files/cache/updater.php | 71 | ||||
-rw-r--r-- | lib/private/files/type/detection.php | 8 |
3 files changed, 69 insertions, 14 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index fc2d965d7f9..c1e5b34c8aa 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -64,6 +64,10 @@ class Cache { * @return int */ public function getMimetypeId($mime) { + if (empty($mime)) { + // Can not insert empty string into Oracle NOT NULL column. + $mime = 'application/octet-stream'; + } if (empty(self::$mimetypeIds)) { $this->loadMimetypes(); } diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1f30173a8f8..da223567001 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -7,6 +7,7 @@ */ namespace OC\Files\Cache; + use OCP\Util; /** @@ -42,6 +43,7 @@ class Updater { $scanner->scan($internalPath, Scanner::SCAN_SHALLOW); $cache->correctFolderSize($internalPath); self::correctFolder($path, $storage->filemtime($internalPath)); + self::correctParentStorageMtime($storage, $internalPath); } } @@ -61,6 +63,7 @@ class Updater { $cache->remove($internalPath); $cache->correctFolderSize($internalPath); self::correctFolder($path, time()); + self::correctParentStorageMtime($storage, $internalPath); } } @@ -87,6 +90,8 @@ class Updater { $cache->correctFolderSize($internalTo); self::correctFolder($from, time()); self::correctFolder($to, time()); + self::correctParentStorageMtime($storageFrom, $internalFrom); + self::correctParentStorageMtime($storageTo, $internalTo); } else { self::deleteUpdate($from); self::writeUpdate($to); @@ -95,6 +100,24 @@ class Updater { } /** + * @brief get file owner and path + * @param string $filename + * @return array with the oweners uid and the owners path + */ + private static function getUidAndFilename($filename) { + + $uid = \OC\Files\Filesystem::getOwner($filename); + \OC\Files\Filesystem::initMountPoints($uid); + + if ($uid != \OCP\User::getUser()) { + $info = \OC\Files\Filesystem::getFileInfo($filename); + $ownerView = new \OC\Files\View('/' . $uid . '/files'); + $filename = $ownerView->getPath($info['fileid']); + } + return array($uid, '/files/' . $filename); + } + + /** * Update the mtime and ETag of all parent folders * * @param string $path @@ -102,29 +125,53 @@ class Updater { */ static public function correctFolder($path, $time) { if ($path !== '' && $path !== '/') { - $parent = dirname($path); - if ($parent === '.' || $parent === '\\') { - $parent = ''; - } + + list($owner, $realPath) = self::getUidAndFilename(dirname($path)); + /** * @var \OC\Files\Storage\Storage $storage * @var string $internalPath */ - list($storage, $internalPath) = self::resolvePath($parent); - if ($storage) { - $cache = $storage->getCache(); - $id = $cache->getId($internalPath); - if ($id !== -1) { - $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); - self::correctFolder($parent, $time); + $view = new \OC\Files\View('/' . $owner); + + list($storage, $internalPath) = $view->resolvePath($realPath); + $cache = $storage->getCache(); + $id = $cache->getId($internalPath); + + while ($id !== -1) { + $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); + if ($realPath !== '') { + $realPath = dirname($realPath); + if($realPath === '/') { + $realPath = ""; + } + // check storage for parent in case we change the storage in this step + list($storage, $internalPath) = $view->resolvePath($realPath); + $cache = $storage->getCache(); + $id = $cache->getId($internalPath); } else { - Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR); + $id = -1; } } } } /** + * update the storage_mtime of the parent + * + * @param \OC\Files\Storage\Storage $storage + * @param string $internalPath + */ + static private function correctParentStorageMtime($storage, $internalPath) { + $cache = $storage->getCache(); + $parentId = $cache->getParentId($internalPath); + $parent = dirname($internalPath); + if ($parentId != -1) { + $cache->update($parentId, array('storage_mtime' => $storage->filemtime($parent))); + } + } + + /** * @param array $params */ static public function writeHook($params) { diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index 242a81cb5a4..d7cc9ebbf4e 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -61,8 +61,6 @@ class Detection { * @return string */ public function detect($path) { - $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); - if (@is_dir($path)) { // directories are easy return "httpd/unix-directory"; @@ -76,9 +74,11 @@ class Detection { $info = @strtolower(finfo_file($finfo, $path)); if ($info) { $mimeType = substr($info, 0, strpos($info, ';')); + return empty($mimeType) ? 'application/octet-stream' : $mimeType; } finfo_close($finfo); } + $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { // use mime magic extension if available $mimeType = mime_content_type($path); @@ -94,6 +94,10 @@ class Detection { //trim the newline $mimeType = trim($reply); + if (empty($mimeType)) { + $mimeType = 'application/octet-stream'; + } + } return $mimeType; } |