From 9d1b425b62af0dc56af473d853d39182a7597a6c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 12:25:48 +0200 Subject: Correct indentation for default language. --- lib/private/l10n.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 3e84c306dc2..38efa88388d 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -447,11 +447,11 @@ 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'])); -- cgit v1.2.3 From 207f6d55ce5047e43f7250ef30b14525dee6bd65 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 12:39:12 +0200 Subject: Fix coding style for else. --- lib/private/l10n.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 38efa88388d..99481404f62 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -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) { @@ -457,8 +456,7 @@ class OC_L10N implements \OCP\IL10N { $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) { -- cgit v1.2.3 From 4c76dd38719f28d6c995047e2ac6154ec20c2ad5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 12:56:51 +0200 Subject: Better variable names. --- lib/private/l10n.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 99481404f62..9f89f0d03e3 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -453,27 +453,27 @@ class OC_L10N implements \OCP\IL10N { } if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - $accepted_languages = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); if(is_array($app)) { $available = $app; } 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) { + $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); + foreach($preferences as $preference) { + list($prefered_language) = explode(';', $preference); + $prefered_language = str_replace('-', '_', $prefered_language); + if( ($key = array_search($prefered_language, $available)) !== false) { if (is_null($app)) { self::$language = $available[$key]; } return $available[$key]; } - foreach($available as $l) { - if ( $temp[0] == substr($l, 0, 2) ) { + foreach($available as $available_language) { + if ($prefered_language == substr($available_language, 0, 2)) { if (is_null($app)) { - self::$language = $l; + self::$language = $available_language; } - return $l; + return $available_language; } } } -- cgit v1.2.3 From c14b470ea24258b0402ad8ee783646d23c6693b9 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:38:22 +0200 Subject: Apply substring on the correct value. --- lib/private/l10n.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 9f89f0d03e3..62827312d32 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -469,7 +469,7 @@ class OC_L10N implements \OCP\IL10N { return $available[$key]; } foreach($available as $available_language) { - if ($prefered_language == substr($available_language, 0, 2)) { + if (substr($prefered_language, 0, 2) === $available_language) { if (is_null($app)) { self::$language = $available_language; } -- cgit v1.2.3 From daf93c45165ac2c73fc1f0d6af513b8c3e497691 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:38:54 +0200 Subject: Sort, so 'de' is preferred over 'de_DE' when performing non-exact matching. --- lib/private/l10n.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 62827312d32..9392cfac05b 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -458,6 +458,10 @@ class OC_L10N implements \OCP\IL10N { } else { $available = self::findAvailableLanguages($app); } + + // 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($prefered_language) = explode(';', $preference); -- cgit v1.2.3 From 06f2ae082eb6fc04b1c6680bd2f35ca1c2032d59 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:39:50 +0200 Subject: Have to also strtolower() on available language name. Otherwise no match. --- lib/private/l10n.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 9392cfac05b..0125dca92ee 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -466,11 +466,13 @@ class OC_L10N implements \OCP\IL10N { foreach($preferences as $preference) { list($prefered_language) = explode(';', $preference); $prefered_language = str_replace('-', '_', $prefered_language); - if( ($key = array_search($prefered_language, $available)) !== false) { - if (is_null($app)) { - self::$language = $available[$key]; + foreach($available as $available_language) { + if ($prefered_language === strtolower($available_language)) { + if (is_null($app)) { + self::$language = $available_language; + } + return $available_language; } - return $available[$key]; } foreach($available as $available_language) { if (substr($prefered_language, 0, 2) === $available_language) { -- cgit v1.2.3 From 54e0f1d739b4b3820cafafca039a3524d3dd28ba Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 23 Oct 2013 19:06:36 +0200 Subject: fixing PHPDoc & grammar --- lib/private/l10n.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 0125dca92ee..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 @@ -464,10 +464,10 @@ class OC_L10N implements \OCP\IL10N { $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); foreach($preferences as $preference) { - list($prefered_language) = explode(';', $preference); - $prefered_language = str_replace('-', '_', $prefered_language); + list($preferred_language) = explode(';', $preference); + $preferred_language = str_replace('-', '_', $preferred_language); foreach($available as $available_language) { - if ($prefered_language === strtolower($available_language)) { + if ($preferred_language === strtolower($available_language)) { if (is_null($app)) { self::$language = $available_language; } @@ -475,7 +475,7 @@ class OC_L10N implements \OCP\IL10N { } } foreach($available as $available_language) { - if (substr($prefered_language, 0, 2) === $available_language) { + if (substr($preferred_language, 0, 2) === $available_language) { if (is_null($app)) { self::$language = $available_language; } -- cgit v1.2.3 From 682d6e8a803d607b42f4179770ee332e1428ba05 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Mon, 28 Oct 2013 14:18:20 +0100 Subject: use SERVERROOT instead of WEBROOT in all file_exists checks, whitespace --- lib/private/urlgenerator.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/private') 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"; -- cgit v1.2.3 From db0fa6c5292003e913aac248e2ee60c77301bd26 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Oct 2013 18:01:37 +0100 Subject: use getHome() to delete users data --- lib/private/user.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/private') diff --git a/lib/private/user.php b/lib/private/user.php index 710f0fd66db..f15fdf1dbbc 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -195,12 +195,12 @@ class OC_User { // 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); + OC_Preferences::deleteUser($uid); // Delete user files in /data/ - OC_Helper::rmdirr(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid . '/'); + OC_Helper::rmdirr(\OC_User::getHome($uid)); // Remove it from the Cache self::getManager()->delete($uid); -- cgit v1.2.3 From a04a01d51f6d9dc9ebc346676048e5988ea1beac Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 29 Oct 2013 12:54:30 +0100 Subject: Do not calculate $isWrapped if not needed. --- lib/private/files/type/detection.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index 242a81cb5a4..d8a83382822 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"; @@ -79,6 +77,7 @@ class Detection { } 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); -- cgit v1.2.3 From 68d13210bdfa4362b984a83795498ff2c764a52b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 29 Oct 2013 13:29:35 +0100 Subject: Reset mimetype to application/octet-stream on empty reply from file command. --- lib/private/files/type/detection.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/private') diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index d8a83382822..e84c63875c9 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -93,6 +93,10 @@ class Detection { //trim the newline $mimeType = trim($reply); + if (empty($mimeType)) { + $mimeType = 'application/octet-stream'; + } + } return $mimeType; } -- cgit v1.2.3 From fa6ae81149974d8becc58903d6c63594ed8b5cb4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 29 Oct 2013 13:36:37 +0100 Subject: Return early if fileinfo is there. --- lib/private/files/type/detection.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/private') diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index e84c63875c9..d7cc9ebbf4e 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -74,6 +74,7 @@ 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); } -- cgit v1.2.3 From b3e39dd3d9d94ed24d0e3e0845fd78ccb52c841d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 29 Oct 2013 14:18:42 +0100 Subject: Map empty mimetypes to octet-stream for Oracle DBMS. --- lib/private/files/cache/cache.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/private') 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(); } -- cgit v1.2.3 From b3626f34cd0df127d742f7a8cb2a4ddf929ff886 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Oct 2013 14:18:57 +0100 Subject: Update the parent folders storage_mtime on write and delete to prevent rescans --- lib/private/files/cache/updater.php | 22 +++++++++++++++++++++- tests/lib/files/cache/updater.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1f30173a8f8..b491b60b0d0 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); @@ -118,12 +123,27 @@ class Updater { $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); self::correctFolder($parent, $time); } else { - Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR); + Util::writeLog('core', 'Path not in cache: ' . $internalPath, Util::ERROR); } } } } + /** + * 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 */ diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 5d7997b0544..a891f2560c4 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -9,6 +9,7 @@ namespace Test\Files\Cache; use \OC\Files\Filesystem as Filesystem; +use OC\Files\Storage\Temporary; class Updater extends \PHPUnit_Framework_TestCase { /** @@ -265,4 +266,35 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertEquals($time, $cachedData['mtime']); } + public function testUpdatePermissionsOnRescanOnlyForUpdatedFile() { + $permissionsCache = $this->storage->getPermissionsCache(); + $scanner = $this->storage->getScanner(); + $scanner->scan(''); + $cache = $this->storage->getCache(); + $loggedInUser = \OC_User::getUser(); + \OC_User::setUserId(self::$user); + FileSystem::getDirectoryContent('/'); + $past = time() - 600; + $cache->put('', array('storage_mtime' => $past)); + + $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user)); + $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + $permissionsCache->set($cache->getId('foo.png'), self::$user, 15); + FileSystem::file_put_contents('/foo.txt', 'asd'); + + $this->assertEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user)); + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + FileSystem::getDirectoryContent('/'); + + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + FileSystem::file_put_contents('/qwerty.txt', 'asd'); + FileSystem::getDirectoryContent('/'); + + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + \OC_User::setUserId($loggedInUser); + } } -- cgit v1.2.3 From fcfac51aa18bdd81be004e63fb98683e2cc780a0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Oct 2013 15:08:12 +0100 Subject: backport of https://github.com/owncloud/core/pull/5513 --- apps/files_encryption/hooks/hooks.php | 62 +++++++++++++++++++++++++++-------- apps/files_sharing/lib/updater.php | 7 ---- lib/private/files/cache/updater.php | 48 ++++++++++++++++++++------- tests/lib/files/cache/updater.php | 18 ++++++++++ 4 files changed, 102 insertions(+), 33 deletions(-) (limited to 'lib/private') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 6e2d360917b..35574b8e5b9 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -35,6 +35,12 @@ class Hooks { * @note This method should never be called for users using client side encryption */ public static function login($params) { + + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + + $l = new \OC_L10N('files_encryption'); $view = new \OC_FilesystemView('/'); @@ -117,11 +123,12 @@ class Hooks { * @note This method should never be called for users using client side encryption */ public static function postCreateUser($params) { - $view = new \OC_FilesystemView('/'); - - $util = new Util($view, $params['uid']); - Helper::setupUser($util, $params['password']); + if (\OCP\App::isEnabled('files_encryption')) { + $view = new \OC_FilesystemView('/'); + $util = new Util($view, $params['uid']); + Helper::setupUser($util, $params['password']); + } } /** @@ -129,26 +136,31 @@ class Hooks { * @note This method should never be called for users using client side encryption */ public static function postDeleteUser($params) { - $view = new \OC_FilesystemView('/'); - // cleanup public key - $publicKey = '/public-keys/' . $params['uid'] . '.public.key'; + if (\OCP\App::isEnabled('files_encryption')) { + $view = new \OC_FilesystemView('/'); - // Disable encryption proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; + // cleanup public key + $publicKey = '/public-keys/' . $params['uid'] . '.public.key'; - $view->unlink($publicKey); + // Disable encryption proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; - \OC_FileProxy::$enabled = $proxyStatus; + $view->unlink($publicKey); + + \OC_FileProxy::$enabled = $proxyStatus; + } } /** * @brief If the password can't be changed within ownCloud, than update the key password in advance. */ public static function preSetPassphrase($params) { - if ( ! \OC_User::canUserChangePassword($params['uid']) ) { - self::setPassphrase($params); + if (\OCP\App::isEnabled('files_encryption')) { + if ( ! \OC_User::canUserChangePassword($params['uid']) ) { + self::setPassphrase($params); + } } } @@ -157,6 +169,11 @@ class Hooks { * @param array $params keys: uid, password */ public static function setPassphrase($params) { + + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + // Only attempt to change passphrase if server-side encryption // is in use (client-side encryption does not have access to // the necessary keys) @@ -227,6 +244,10 @@ class Hooks { */ public static function preShared($params) { + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + $l = new \OC_L10N('files_encryption'); $users = array(); $view = new \OC\Files\View('/public-keys/'); @@ -278,6 +299,10 @@ class Hooks { // [run] => whether emitting script should continue to run // TODO: Should other kinds of item be encrypted too? + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $view = new \OC_FilesystemView('/'); @@ -372,6 +397,10 @@ class Hooks { // [shareWith] => test1 // [itemParent] => + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $view = new \OC_FilesystemView('/'); @@ -453,6 +482,11 @@ class Hooks { * of the stored versions along the actual file */ public static function postRename($params) { + + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 3381f75f16d..171999ea652 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -49,13 +49,6 @@ class Shared_Updater { } $users = $reshareUsers; } - // Correct folders of shared file owner - $target = substr($target, 8); - if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) { - \OC\Files\Filesystem::initMountPoints($uidOwner); - $source = '/'.$uidOwner.'/'.$source['path']; - \OC\Files\Cache\Updater::correctFolder($source, $info['mtime']); - } } } diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1f30173a8f8..6d016f9deac 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -94,6 +94,24 @@ class Updater { } } + /** + * @brief get file owner and path + * @param string $filename + * @return array with the oweners uid and the owners path + */ + public 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 * @@ -102,23 +120,29 @@ 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))); + $realPath = dirname($realPath); + // check storage for parent in case we change the storage in this step + list($storage, $internalPath) = $view->resolvePath($realPath); + if ($internalPath) { + $cache = $storage->getCache(); + $id = $cache->getId($internalPath); } else { - Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR); + $id = -1; } } } diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 5d7997b0544..9c1c6f8d18f 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -21,6 +21,8 @@ class Updater extends \PHPUnit_Framework_TestCase { */ private $scanner; + private $stateFilesEncryption; + /** * @var \OC\Files\Cache\Cache $cache */ @@ -29,6 +31,12 @@ class Updater extends \PHPUnit_Framework_TestCase { private static $user; public function setUp() { + + // remember files_encryption state + $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption'); + // we want to tests with the encryption app disabled + \OC_App::disable('files_encryption'); + $this->storage = new \OC\Files\Storage\Temporary(array()); $textData = "dummy file data\n"; $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); @@ -46,6 +54,10 @@ class Updater extends \PHPUnit_Framework_TestCase { if (!self::$user) { self::$user = uniqid(); } + + \OC_User::createUser(self::$user, 'password'); + \OC_User::setUserId(self::$user); + \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); @@ -63,7 +75,13 @@ class Updater extends \PHPUnit_Framework_TestCase { if ($this->cache) { $this->cache->clear(); } + $result = \OC_User::deleteUser(self::$user); + $this->assertTrue($result); Filesystem::tearDown(); + // reset app files_encryption + if ($this->stateFilesEncryption) { + \OC_App::enable('files_encryption'); + } } public function testWrite() { -- cgit v1.2.3 From a80ac9c4923a48a0d180a9ae8651bd84ea94c678 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Oct 2013 15:10:02 +0100 Subject: make getUidAndFilename() private --- lib/private/files/cache/updater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 6d016f9deac..e711b21e340 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -99,7 +99,7 @@ class Updater { * @param string $filename * @return array with the oweners uid and the owners path */ - public static function getUidAndFilename($filename) { + private static function getUidAndFilename($filename) { $uid = \OC\Files\Filesystem::getOwner($filename); \OC\Files\Filesystem::initMountPoints($uid); -- cgit v1.2.3 From f021dad204afab2977417265f121d660d3d71252 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Oct 2013 15:50:33 +0100 Subject: remove user from cache if he was deleted successfully --- lib/private/user.php | 25 ++++++++++++++++--------- lib/private/user/manager.php | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) (limited to 'lib/private') diff --git a/lib/private/user.php b/lib/private/user.php index 6b350d4cf1b..710f0fd66db 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_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $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 @@ -118,6 +118,20 @@ class Manager extends PublicEmitter { return ($user !== null); } + /** + * 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 * -- cgit v1.2.3 From 0d7d396d8013d77027d50a6c54350690416d344c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Oct 2013 16:30:47 +0100 Subject: make sure that also the storage etag gets changed --- lib/private/files/cache/updater.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index e711b21e340..48fb3ba6c5c 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -135,10 +135,13 @@ class Updater { while ($id !== -1) { $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); - $realPath = dirname($realPath); - // check storage for parent in case we change the storage in this step - list($storage, $internalPath) = $view->resolvePath($realPath); - if ($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 { -- cgit v1.2.3 From 3d42e402c5f1956bc72ac5accc268f519d66c3e9 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 29 Oct 2013 23:07:27 +0100 Subject: http header OCS-ApiRequest: true is required in case of session based OCS API calls --- lib/private/api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/api.php b/lib/private/api.php index 26091657b31..0576f3e3f93 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['OCS_APIREQUEST']) ? $_SERVER['OCS_APIREQUEST'] === 'true' : false; + if ($loggedIn === true && $ocsApiRequest) { return OC_User::getUser(); } -- cgit v1.2.3 From cba12e009fd11591763198665e5845cc54f395da Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 30 Oct 2013 21:07:19 +0100 Subject: Added missing HTTP prefix to the $_SERVER variable --- lib/private/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/api.php b/lib/private/api.php index 0576f3e3f93..7e69a6a77d2 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -250,7 +250,7 @@ class OC_API { // reuse existing login $loggedIn = OC_User::isLoggedIn(); - $ocsApiRequest = isset($_SERVER['OCS_APIREQUEST']) ? $_SERVER['OCS_APIREQUEST'] === 'true' : false; + $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; if ($loggedIn === true && $ocsApiRequest) { return OC_User::getUser(); } -- cgit v1.2.3