diff options
-rw-r--r-- | apps/files_sharing/api/share20ocs.php | 72 | ||||
-rw-r--r-- | apps/files_sharing/tests/api/share20ocstest.php | 193 | ||||
-rw-r--r-- | core/Command/Log/Manage.php | 2 | ||||
-rw-r--r-- | lib/private/Log.php | 2 | ||||
-rw-r--r-- | lib/private/Log/ErrorHandler.php (renamed from lib/private/log/errorhandler.php) | 0 | ||||
-rw-r--r-- | lib/private/Log/Errorlog.php (renamed from lib/private/log/errorlog.php) | 4 | ||||
-rw-r--r-- | lib/private/Log/Owncloud.php (renamed from lib/private/log/owncloud.php) | 16 | ||||
-rw-r--r-- | lib/private/Log/Rotate.php (renamed from lib/private/log/rotate.php) | 0 | ||||
-rw-r--r-- | lib/private/Log/Syslog.php (renamed from lib/private/log/syslog.php) | 4 | ||||
-rw-r--r-- | lib/private/Server.php | 2 | ||||
-rw-r--r-- | lib/private/user/database.php | 12 | ||||
-rw-r--r-- | settings/Controller/LogSettingsController.php | 2 | ||||
-rw-r--r-- | tests/lib/log/owncloud.php | 15 |
13 files changed, 262 insertions, 62 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 68098530017..af762845326 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -28,11 +28,12 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\Files\IRootFolder; +use OCP\Lock\LockedException; use OCP\Share; use OCP\Share\IManager; - use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\GenericShareException; +use OCP\Lock\ILockingProvider; /** * Class Share20OCS @@ -205,12 +206,21 @@ class Share20OCS { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } + try { + $share->getNode()->lock(ILockingProvider::LOCK_SHARED); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, 'could not delete share'); + } + if (!$this->canAccessShare($share)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Could not delete share')); } $this->shareManager->deleteShare($share); + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); + return new \OC_OCS_Result(); } @@ -233,12 +243,18 @@ class Share20OCS { $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); try { $path = $userFolder->get($path); - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong path, file/folder doesn\'t exist')); } $share->setNode($path); + try { + $share->getNode()->lock(ILockingProvider::LOCK_SHARED); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, 'Could not create share'); + } + // Parse permissions (if available) $permissions = $this->request->getParam('permissions', null); if ($permissions === null) { @@ -248,6 +264,7 @@ class Share20OCS { } if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, 'invalid permissions'); } @@ -275,17 +292,20 @@ class Share20OCS { if ($shareType === \OCP\Share::SHARE_TYPE_USER) { // Valid user is required to share if ($shareWith === null || !$this->userManager->userExists($shareWith)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Please specify a valid user')); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { if (!$this->shareManager->allowGroupSharing()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Group sharing is disabled by the administrator')); } // Valid group is required to share if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Please specify a valid group')); } $share->setSharedWith($shareWith); @@ -293,6 +313,7 @@ class Share20OCS { } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { //Can we even share links? if (!$this->shareManager->shareApiAllowLinks()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Public link sharing is disabled by the administrator')); } @@ -302,6 +323,7 @@ class Share20OCS { */ $existingShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); if (!empty($existingShares)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result($this->formatShare($existingShares[0])); } @@ -309,11 +331,13 @@ class Share20OCS { if ($publicUpload === 'true') { // Check if public upload is allowed if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $this->l->t('Public upload disabled by the administrator')); } // Public upload can only be set for folders if ($path instanceof \OCP\Files\File) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Public upload is only possible for publicly shared folders')); } @@ -341,18 +365,21 @@ class Share20OCS { $expireDate = $this->parseDate($expireDate); $share->setExpirationDate($expireDate); } catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Invalid date, date format must be YYYY-MM-DD')); } } } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); } else { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Unknown share type')); } @@ -363,13 +390,18 @@ class Share20OCS { $share = $this->shareManager->createShare($share); } catch (GenericShareException $e) { $code = $e->getCode() === 0 ? 403 : $e->getCode(); + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, $code, $e->getHint()); }catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $e->getMessage()); } - $share = $this->formatShare($share); - return new \OC_OCS_Result($share); + $output = $this->formatShare($share); + + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + return new \OC_OCS_Result($output); } /** @@ -454,17 +486,28 @@ class Share20OCS { $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); try { $path = $userFolder->get($path); + $path->lock(ILockingProvider::LOCK_SHARED); } catch (\OCP\Files\NotFoundException $e) { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong path, file/folder doesn\'t exist')); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, $this->l->t('Could not lock path')); } } if ($sharedWithMe === 'true') { - return $this->getSharedWithMe($path); + $result = $this->getSharedWithMe($path); + if ($path !== null) { + $path->unlock(ILockingProvider::LOCK_SHARED); + } + return $result; } if ($subfiles === 'true') { - return $this->getSharesInDir($path); + $result = $this->getSharesInDir($path); + if ($path !== null) { + $path->unlock(ILockingProvider::LOCK_SHARED); + } + return $result; } if ($reshares === 'true') { @@ -494,6 +537,10 @@ class Share20OCS { } } + if ($path !== null) { + $path->unlock(ILockingProvider::LOCK_SHARED); + } + return new \OC_OCS_Result($formatted); } @@ -512,7 +559,10 @@ class Share20OCS { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } + $share->getNode()->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + if (!$this->canAccessShare($share)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } @@ -526,6 +576,7 @@ class Share20OCS { */ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given'); } @@ -543,15 +594,18 @@ class Share20OCS { if ($newPermissions !== null && $newPermissions !== \OCP\Constants::PERMISSION_READ && $newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Can\'t change permissions for public share links')); } if ($newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) { if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $this->l->t('Public upload disabled by the administrator')); } if (!($share->getNode() instanceof \OCP\Files\Folder)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Public upload is only possible for publicly shared folders')); } } @@ -566,6 +620,7 @@ class Share20OCS { try { $expireDate = $this->parseDate($expireDate); } catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $e->getMessage()); } $share->setExpirationDate($expireDate); @@ -580,6 +635,7 @@ class Share20OCS { } else { // For other shares only permissions is valid. if ($permissions === null) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Wrong or no update parameter given')); } else { $permissions = (int)$permissions; @@ -599,6 +655,7 @@ class Share20OCS { } if ($share->getPermissions() & ~$maxPermissions) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Cannot increase permissions')); } } @@ -608,9 +665,12 @@ class Share20OCS { try { $share = $this->shareManager->updateShare($share); } catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $e->getMessage()); } + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + return new \OC_OCS_Result($this->formatShare($share)); } diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php index 56c350aa99a..ffb74da2af7 100644 --- a/apps/files_sharing/tests/api/share20ocstest.php +++ b/apps/files_sharing/tests/api/share20ocstest.php @@ -29,6 +29,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\Files\IRootFolder; +use OCP\Lock\LockedException; /** * Class Share20OCSTest @@ -137,8 +138,11 @@ class Share20OCSTest extends \Test\TestCase { } public function testDeleteShare() { + $node = $this->getMock('\OCP\Files\File'); + $share = $this->newShare(); - $share->setSharedBy($this->currentUser->getUID()); + $share->setSharedBy($this->currentUser->getUID()) + ->setNode($node); $this->shareManager ->expects($this->once()) ->method('getShareById') @@ -149,10 +153,45 @@ class Share20OCSTest extends \Test\TestCase { ->method('deleteShare') ->with($share); + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $expected = new \OC_OCS_Result(); $this->assertEquals($expected, $this->ocs->deleteShare(42)); } + public function testDeleteShareLocked() { + $node = $this->getMock('\OCP\Files\File'); + + $share = $this->newShare(); + $share->setSharedBy($this->currentUser->getUID()) + ->setNode($node); + $this->shareManager + ->expects($this->once()) + ->method('getShareById') + ->with('ocinternal:42') + ->willReturn($share); + $this->shareManager + ->expects($this->never()) + ->method('deleteShare') + ->with($share); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED) + ->will($this->throwException(new LockedException('mypath'))); + $node->expects($this->never()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + $expected = new \OC_OCS_Result(null, 404, 'could not delete share'); + $this->assertEquals($expected, $this->ocs->deleteShare(42)); + } + /* * FIXME: Enable once we have a federated Share Provider @@ -526,7 +565,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareInvalidPermissions() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -548,6 +587,10 @@ class Share20OCSTest extends \Test\TestCase { ->with('valid-path') ->willReturn($path); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $expected = new \OC_OCS_Result(null, 404, 'invalid permissions'); $result = $this->ocs->createShare(); @@ -557,7 +600,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUserNoShareWith() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -585,6 +628,10 @@ class Share20OCSTest extends \Test\TestCase { ->with('valid-path') ->willReturn($path); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user'); $result = $this->ocs->createShare(); @@ -594,7 +641,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUserNoValidShareWith() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -625,6 +672,10 @@ class Share20OCSTest extends \Test\TestCase { $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -632,9 +683,8 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUser() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); - $this->shareManager->method('createShare')->will($this->returnArgument(0)); $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ @@ -677,15 +727,26 @@ class Share20OCSTest extends \Test\TestCase { $this->userManager->method('userExists')->with('validUser')->willReturn(true); - $share->method('setNode')->with($path); - $share->method('setPermissions') - ->with( - \OCP\Constants::PERMISSION_ALL & - ~\OCP\Constants::PERMISSION_DELETE & - ~\OCP\Constants::PERMISSION_CREATE); - $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_USER); - $share->method('setSharedWith')->with('validUser'); - $share->method('setSharedBy')->with('currentUser'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $path->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + $this->shareManager->method('createShare') + ->with($this->callback(function (\OCP\Share\IShare $share) use ($path) { + return $share->getNode() === $path && + $share->getPermissions() === ( + \OCP\Constants::PERMISSION_ALL & + ~\OCP\Constants::PERMISSION_DELETE & + ~\OCP\Constants::PERMISSION_CREATE + ) && + $share->getShareType() === \OCP\Share::SHARE_TYPE_USER && + $share->getSharedWith() === 'validUser' && + $share->getSharedBy() === 'currentUser'; + })) + ->will($this->returnArgument(0)); $expected = new \OC_OCS_Result(); $result = $ocs->createShare(); @@ -695,7 +756,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroupNoValidShareWith() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('createShare')->will($this->returnArgument(0)); @@ -727,6 +788,10 @@ class Share20OCSTest extends \Test\TestCase { $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -734,9 +799,8 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroup() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); - $this->shareManager->method('createShare')->will($this->returnArgument(0)); $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ @@ -783,11 +847,22 @@ class Share20OCSTest extends \Test\TestCase { ->method('allowGroupSharing') ->willReturn(true); - $share->method('setNode')->with($path); - $share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL); - $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP); - $share->method('setSharedWith')->with('validGroup'); - $share->method('setSharedBy')->with('currentUser'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $path->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + $this->shareManager->method('createShare') + ->with($this->callback(function (\OCP\Share\IShare $share) use ($path) { + return $share->getNode() === $path && + $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && + $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && + $share->getSharedWith() === 'validGroup' && + $share->getSharedBy() === 'currentUser'; + })) + ->will($this->returnArgument(0)); $expected = new \OC_OCS_Result(); $result = $ocs->createShare(); @@ -797,7 +872,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroupNotAllowed() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -832,9 +907,8 @@ class Share20OCSTest extends \Test\TestCase { ->method('allowGroupSharing') ->willReturn(false); - $share->method('setNode')->with($path); - $expected = new \OC_OCS_Result(null, 404, 'Group sharing is disabled by the administrator'); + $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1154,7 +1228,13 @@ class Share20OCSTest extends \Test\TestCase { } public function testUpdateShareCantAccess() { - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); + $share->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1166,10 +1246,16 @@ class Share20OCSTest extends \Test\TestCase { } public function testUpdateNoParametersLink() { - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) - ->setShareType(\OCP\Share::SHARE_TYPE_LINK); + ->setShareType(\OCP\Share::SHARE_TYPE_LINK) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1181,10 +1267,16 @@ class Share20OCSTest extends \Test\TestCase { } public function testUpdateNoParametersOther() { - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) - ->setShareType(\OCP\Share::SHARE_TYPE_GROUP); + ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1198,13 +1290,22 @@ class Share20OCSTest extends \Test\TestCase { public function testUpdateLinkShareClear() { $ocs = $this->mockFormatShare(); - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate(new \DateTime()) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); + ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->request ->method('getParam') @@ -1364,13 +1465,22 @@ class Share20OCSTest extends \Test\TestCase { $date = new \DateTime('2000-01-01'); $date->setTime(0,0,0); - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\File'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); + ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->request ->method('getParam') @@ -1398,13 +1508,15 @@ class Share20OCSTest extends \Test\TestCase { public function testUpdateLinkShareExpireDateDoesNotChangeOther() { $ocs = $this->mockFormatShare(); - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\File'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate(new \DateTime()) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); + ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setNode($node); $this->request ->method('getParam') @@ -1412,6 +1524,13 @@ class Share20OCSTest extends \Test\TestCase { ['expireDate', null, '2010-12-23'], ])); + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->expects($this->once())->method('updateShare')->with( diff --git a/core/Command/Log/Manage.php b/core/Command/Log/Manage.php index 1d65d7ed0d8..aeaaca8aa0e 100644 --- a/core/Command/Log/Manage.php +++ b/core/Command/Log/Manage.php @@ -115,7 +115,7 @@ class Manage extends Command { * @throws \InvalidArgumentException */ protected function validateBackend($backend) { - if (!class_exists('OC_Log_'.$backend)) { + if (!class_exists('OC\\Log\\'.ucfirst($backend))) { throw new \InvalidArgumentException('Invalid backend'); } } diff --git a/lib/private/Log.php b/lib/private/Log.php index d82346bbcf0..9248070c067 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -73,7 +73,7 @@ class Log implements ILogger { // FIXME: Add this for backwards compatibility, should be fixed at some point probably if($logger === null) { - $this->logger = 'OC_Log_'.ucfirst($this->config->getValue('log_type', 'owncloud')); + $this->logger = 'OC\\Log\\'.ucfirst($this->config->getValue('log_type', 'owncloud')); call_user_func(array($this->logger, 'init')); } else { $this->logger = $logger; diff --git a/lib/private/log/errorhandler.php b/lib/private/Log/ErrorHandler.php index 8899bcfcb03..8899bcfcb03 100644 --- a/lib/private/log/errorhandler.php +++ b/lib/private/Log/ErrorHandler.php diff --git a/lib/private/log/errorlog.php b/lib/private/Log/Errorlog.php index ad3605136d0..37498c36aba 100644 --- a/lib/private/log/errorlog.php +++ b/lib/private/Log/Errorlog.php @@ -23,7 +23,9 @@ * THE SOFTWARE. */ -class OC_Log_Errorlog { +namespace OC\Log; + +class Errorlog { /** diff --git a/lib/private/log/owncloud.php b/lib/private/Log/Owncloud.php index 9c106299e4c..13997a0d552 100644 --- a/lib/private/log/owncloud.php +++ b/lib/private/Log/Owncloud.php @@ -27,13 +27,15 @@ * */ +namespace OC\Log; + /** * logging utilities * * Log is saved at data/owncloud.log (on default) */ -class OC_Log_Owncloud { +class Owncloud { static protected $logFile; /** @@ -41,7 +43,7 @@ class OC_Log_Owncloud { */ public static function init() { $systemConfig = \OC::$server->getSystemConfig(); - $defaultLogFile = $systemConfig->getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log'; + $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/owncloud.log'; self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile); /** @@ -72,13 +74,13 @@ class OC_Log_Owncloud { $format = $config->getValue('logdateformat', 'c'); $logTimeZone = $config->getValue( "logtimezone", 'UTC' ); try { - $timezone = new DateTimeZone($logTimeZone); - } catch (Exception $e) { - $timezone = new DateTimeZone('UTC'); + $timezone = new \DateTimeZone($logTimeZone); + } catch (\Exception $e) { + $timezone = new \DateTimeZone('UTC'); } - $time = DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); + $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); if ($time === false) { - $time = new DateTime(null, $timezone); + $time = new \DateTime(null, $timezone); } else { // apply timezone if $time is created from UNIX timestamp $time->setTimezone($timezone); diff --git a/lib/private/log/rotate.php b/lib/private/Log/Rotate.php index 458661c82d0..458661c82d0 100644 --- a/lib/private/log/rotate.php +++ b/lib/private/Log/Rotate.php diff --git a/lib/private/log/syslog.php b/lib/private/Log/Syslog.php index 96cf463d042..115103f26d6 100644 --- a/lib/private/log/syslog.php +++ b/lib/private/Log/Syslog.php @@ -21,7 +21,9 @@ * */ -class OC_Log_Syslog { +namespace OC\Log; + +class Syslog { static protected $levels = array( \OCP\Util::DEBUG => LOG_DEBUG, \OCP\Util::INFO => LOG_INFO, diff --git a/lib/private/Server.php b/lib/private/Server.php index afe4939dee0..bbe6b88876f 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -329,7 +329,7 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerService('Logger', function (Server $c) { $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); - $logger = 'OC_Log_' . ucfirst($logClass); + $logger = 'OC\\Log\\' . ucfirst($logClass); call_user_func(array($logger, 'init')); return new Log($logger); diff --git a/lib/private/user/database.php b/lib/private/user/database.php index 22a05090b96..fd273055ae1 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -48,11 +48,21 @@ * */ +use OC\Cache\CappedMemoryCache; + /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { - private $cache = array(); + /** @var CappedMemoryCache */ + private $cache; + + /** + * OC_User_Database constructor. + */ + public function __construct() { + $this->cache = new CappedMemoryCache(); + } /** * Create a new user diff --git a/settings/Controller/LogSettingsController.php b/settings/Controller/LogSettingsController.php index c0c9ee04ca3..70a2b752359 100644 --- a/settings/Controller/LogSettingsController.php +++ b/settings/Controller/LogSettingsController.php @@ -102,7 +102,7 @@ class LogSettingsController extends Controller { * @return StreamResponse */ public function download() { - $resp = new StreamResponse(\OC_Log_Owncloud::getLogFilePath()); + $resp = new StreamResponse(\OC\Log\Owncloud::getLogFilePath()); $resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"'); return $resp; } diff --git a/tests/lib/log/owncloud.php b/tests/lib/log/owncloud.php index adecc49768c..e19063a83f5 100644 --- a/tests/lib/log/owncloud.php +++ b/tests/lib/log/owncloud.php @@ -15,12 +15,17 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ +namespace Test\Log; + +use OC\Log\Owncloud; +use Test\TestCase; + /** - * Class Test_Log_Owncloud + * Class OwncloudTest * * @group DB */ -class Test_Log_Owncloud extends Test\TestCase +class OwncloudTest extends TestCase { private $restore_logfile; private $restore_logdateformat; @@ -32,7 +37,7 @@ class Test_Log_Owncloud extends Test\TestCase $this->restore_logdateformat = $config->getSystemValue('logdateformat'); $config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest"); - OC_Log_Owncloud::init(); + Owncloud::init(); } protected function tearDown() { $config = \OC::$server->getConfig(); @@ -46,7 +51,7 @@ class Test_Log_Owncloud extends Test\TestCase } else { $config->deleteSystemValue("restore_logdateformat"); } - OC_Log_Owncloud::init(); + Owncloud::init(); parent::tearDown(); } @@ -57,7 +62,7 @@ class Test_Log_Owncloud extends Test\TestCase # set format & write log line $config->setSystemValue('logdateformat', 'u'); - OC_Log_Owncloud::write('test', 'message', \OCP\Util::ERROR); + Owncloud::write('test', 'message', \OCP\Util::ERROR); # read log line $handle = @fopen($config->getSystemValue('logfile'), 'r'); |