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 | |
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')
-rw-r--r-- | lib/private/api.php | 3 | ||||
-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 | ||||
-rw-r--r-- | lib/private/l10n.php | 46 | ||||
-rw-r--r-- | lib/private/urlgenerator.php | 10 | ||||
-rw-r--r-- | lib/private/user.php | 25 | ||||
-rw-r--r-- | lib/private/user/manager.php | 14 |
8 files changed, 131 insertions, 50 deletions
diff --git a/lib/private/api.php b/lib/private/api.php index 26091657b31..7e69a6a77d2 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -250,7 +250,8 @@ class OC_API { // reuse existing login $loggedIn = OC_User::isLoggedIn(); - if ($loggedIn === true) { + $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; + if ($loggedIn === true && $ocsApiRequest) { return OC_User::getUser(); } 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; } diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 3e84c306dc2..2d440850459 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -419,7 +419,7 @@ class OC_L10N implements \OCP\IL10N { /** * @brief find the best language * @param $app Array or string, details below - * @returns language + * @returns string language * * If $app is an array, ownCloud assumes that these are the available * languages. Otherwise ownCloud tries to find the files in the l10n @@ -438,8 +438,7 @@ class OC_L10N implements \OCP\IL10N { if(is_array($app)) { $available = $app; $lang_exists = array_search($lang, $available) !== false; - } - else { + } else { $lang_exists = self::languageExists($app, $lang); } if($lang_exists) { @@ -447,35 +446,40 @@ class OC_L10N implements \OCP\IL10N { } } - $default_language = OC_Config::getValue('default_language', false); + $default_language = OC_Config::getValue('default_language', false); - if($default_language !== false) { - return $default_language; - } + if($default_language !== false) { + return $default_language; + } if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - $accepted_languages = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); if(is_array($app)) { $available = $app; - } - else{ + } else { $available = self::findAvailableLanguages($app); } - foreach($accepted_languages as $i) { - $temp = explode(';', $i); - $temp[0] = str_replace('-', '_', $temp[0]); - if( ($key = array_search($temp[0], $available)) !== false) { - if (is_null($app)) { - self::$language = $available[$key]; + + // E.g. make sure that 'de' is before 'de_DE'. + sort($available); + + $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); + foreach($preferences as $preference) { + list($preferred_language) = explode(';', $preference); + $preferred_language = str_replace('-', '_', $preferred_language); + foreach($available as $available_language) { + if ($preferred_language === strtolower($available_language)) { + if (is_null($app)) { + self::$language = $available_language; + } + return $available_language; } - return $available[$key]; } - foreach($available as $l) { - if ( $temp[0] == substr($l, 0, 2) ) { + foreach($available as $available_language) { + if (substr($preferred_language, 0, 2) === $available_language) { if (is_null($app)) { - self::$language = $l; + self::$language = $available_language; } - return $l; + return $available_language; } } } diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php index 1ec10fe5688..7795011fd06 100644 --- a/lib/private/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -88,27 +88,27 @@ class URLGenerator implements IURLGenerator { if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { return \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") - && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { + && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { return \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; } elseif (file_exists(\OC_App::getAppPath($app) . "/img/$image")) { return \OC_App::getAppWebPath($app) . "/img/$image"; } elseif (!file_exists(\OC_App::getAppPath($app) . "/img/$basename.svg") - && file_exists(\OC_App::getAppPath($app) . "/img/$basename.png")) { + && file_exists(\OC_App::getAppPath($app) . "/img/$basename.png")) { return \OC_App::getAppPath($app) . "/img/$basename.png"; } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { return \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") - && file_exists(\OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"))) { + && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { return \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { return \OC::$WEBROOT . "/$app/img/$image"; } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") - && file_exists(\OC::$WEBROOT . "/$app/img/$basename.png"))) { + && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { return \OC::$WEBROOT . "/$app/img/$basename.png"; } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { return \OC::$WEBROOT . "/themes/$theme/core/img/$image"; } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") - && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { + && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { return \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { return \OC::$WEBROOT . "/core/img/$image"; diff --git a/lib/private/user.php b/lib/private/user.php index 6b350d4cf1b..f15fdf1dbbc 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -187,18 +187,25 @@ class OC_User { public static function deleteUser($uid) { $user = self::getManager()->get($uid); if ($user) { - $user->delete(); + $result = $user->delete(); - // We have to delete the user from all groups - foreach (OC_Group::getUserGroups($uid) as $i) { - OC_Group::removeFromGroup($uid, $i); + // if delete was successful we clean-up the rest + if ($result) { + + // We have to delete the user from all groups + foreach (OC_Group::getUserGroups($uid) as $i) { + OC_Group::removeFromGroup($uid, $i); + } + // Delete the user's keys in preferences + OC_Preferences::deleteUser($uid); + + // Delete user files in /data/ + OC_Helper::rmdirr(\OC_User::getHome($uid)); + + // Remove it from the Cache + self::getManager()->delete($uid); } - // Delete the user's keys in preferences - OC_Preferences::deleteUser($uid); - // Delete user files in /data/ - OC_Helper::rmdirr(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid . '/'); - return true; } else { return false; diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 13286bc28a4..703c8cd7413 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -119,6 +119,20 @@ class Manager extends PublicEmitter { } /** + * remove deleted user from cache + * + * @param string $uid + * @return bool + */ + public function delete($uid) { + if (isset($this->cachedUsers[$uid])) { + unset($this->cachedUsers[$uid]); + return true; + } + return false; + } + + /** * Check if the password is valid for the user * * @param $loginname |