summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-06-24 18:37:48 +0200
committerVincent Petry <pvince81@owncloud.com>2015-06-24 18:37:48 +0200
commit58439c337c2e242c199f153d0529e0b0b482f03a (patch)
tree7a3bb39b99c1f0415f7a5a6bb5a76fd3f74d2dec /tests/lib
parent5f59393b30f9132b48d828387838847cea6026a5 (diff)
parent8859004a2bb1a65d71553b55562c79d9a20cfb3e (diff)
downloadnextcloud-server-58439c337c2e242c199f153d0529e0b0b482f03a.tar.gz
nextcloud-server-58439c337c2e242c199f153d0529e0b0b482f03a.zip
Merge pull request #17070 from owncloud/lock-movemountbug
Lock correct paths when moving mount
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/files/view.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 9862026495f..42768a0b274 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -1162,6 +1162,97 @@ class View extends \Test\TestCase {
$this->assertFalse($view->lockFile($pathPrefix . '/foo/bar', ILockingProvider::LOCK_EXCLUSIVE));
}
+ /**
+ * Test that locks are on mount point paths instead of mount root
+ */
+ public function testLockLocalMountPointPathInsteadOfStorageRoot() {
+ $lockingProvider = \OC::$server->getLockingProvider();
+ $view = new \OC\Files\View('/testuser/files/');
+ $storage = new Temporary([]);
+ \OC\Files\Filesystem::mount($storage, [], '/');
+ $mountedStorage = new Temporary([]);
+ \OC\Files\Filesystem::mount($mountedStorage, [], '/testuser/files/mountpoint');
+
+ $this->assertTrue(
+ $view->lockFile('/mountpoint', ILockingProvider::LOCK_EXCLUSIVE, true),
+ 'Can lock mount point'
+ );
+
+ // no exception here because storage root was not locked
+ $mountedStorage->acquireLock('', ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
+
+ $thrown = false;
+ try {
+ $storage->acquireLock('/testuser/files/mountpoint', ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
+ } catch (\OCP\Lock\LockedException $e) {
+ $thrown = true;
+ }
+ $this->assertTrue($thrown, 'Mount point path was locked on root storage');
+
+ $lockingProvider->releaseAll();
+ }
+
+ /**
+ * Test that locks are on mount point paths and also mount root when requested
+ */
+ public function testLockStorageRootButNotLocalMountPoint() {
+ $lockingProvider = \OC::$server->getLockingProvider();
+ $view = new \OC\Files\View('/testuser/files/');
+ $storage = new Temporary([]);
+ \OC\Files\Filesystem::mount($storage, [], '/');
+ $mountedStorage = new Temporary([]);
+ \OC\Files\Filesystem::mount($mountedStorage, [], '/testuser/files/mountpoint');
+
+ $this->assertTrue(
+ $view->lockFile('/mountpoint', ILockingProvider::LOCK_EXCLUSIVE, false),
+ 'Can lock mount point'
+ );
+
+ $thrown = false;
+ try {
+ $mountedStorage->acquireLock('', ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
+ } catch (\OCP\Lock\LockedException $e) {
+ $thrown = true;
+ }
+ $this->assertTrue($thrown, 'Mount point storage root was locked on original storage');
+
+ // local mount point was not locked
+ $storage->acquireLock('/testuser/files/mountpoint', ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
+
+ $lockingProvider->releaseAll();
+ }
+
+ /**
+ * Test that locks are on mount point paths and also mount root when requested
+ */
+ public function testLockMountPointPathFailReleasesBoth() {
+ $lockingProvider = \OC::$server->getLockingProvider();
+ $view = new \OC\Files\View('/testuser/files/');
+ $storage = new Temporary([]);
+ \OC\Files\Filesystem::mount($storage, [], '/');
+ $mountedStorage = new Temporary([]);
+ \OC\Files\Filesystem::mount($mountedStorage, [], '/testuser/files/mountpoint.txt');
+
+ // this would happen if someone is writing on the mount point
+ $mountedStorage->acquireLock('', ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
+
+ $thrown = false;
+ try {
+ // this actually acquires two locks, one on the mount point and one no the storage root,
+ // but the one on the storage root will fail
+ $view->lockFile('/mountpoint.txt', ILockingProvider::LOCK_SHARED);
+ } catch (\OCP\Lock\LockedException $e) {
+ $thrown = true;
+ }
+ $this->assertTrue($thrown, 'Cannot acquire shared lock because storage root is already locked');
+
+ // from here we expect that the lock on the local mount point was released properly
+ // so acquiring an exclusive lock will succeed
+ $storage->acquireLock('/testuser/files/mountpoint.txt', ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
+
+ $lockingProvider->releaseAll();
+ }
+
public function dataLockPaths() {
return [
['/testuser/{folder}', ''],