aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/testcase.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-06-12 18:50:49 +0200
committerVincent Petry <pvince81@owncloud.com>2015-06-12 18:52:18 +0200
commit4497aa4c68051ff75d1587dc1b01676926dfb466 (patch)
treee298734f2f3ed0abcc19e45db284f6c1e2ca427a /tests/lib/testcase.php
parentbb0ea6336df84d391c0d972a56f27077f632948c (diff)
downloadnextcloud-server-4497aa4c68051ff75d1587dc1b01676926dfb466.tar.gz
nextcloud-server-4497aa4c68051ff75d1587dc1b01676926dfb466.zip
Webdav PUT small file lock must be shared during hooks
Fixed code path for Webdav PUT of small files to use shared locks during hook execution, and exclusive during the file operation This makes it possible for versions to be copied by accessing the file in a post_write hook.
Diffstat (limited to 'tests/lib/testcase.php')
-rw-r--r--tests/lib/testcase.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 8551edab71f..d385a903d1e 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -242,4 +242,39 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
\OC_Util::setupFS($user);
}
}
+
+ /**
+ * Check if the given path is locked with a given type
+ *
+ * @param \OC\Files\View $view view
+ * @param string $path path to check
+ * @param int $type lock type
+ *
+ * @return boolean true if the file is locked with the
+ * given type, false otherwise
+ */
+ protected function isFileLocked($view, $path, $type) {
+ // Note: this seems convoluted but is necessary because
+ // the format of the lock key depends on the storage implementation
+ // (in our case mostly md5)
+
+ if ($type === \OCP\Lock\ILockingProvider::LOCK_SHARED) {
+ // to check if the file has a shared lock, try acquiring an exclusive lock
+ $checkType = \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE;
+ } else {
+ // a shared lock cannot be set if exclusive lock is in place
+ $checkType = \OCP\Lock\ILockingProvider::LOCK_SHARED;
+ }
+ try {
+ $view->lockFile($path, $checkType);
+ // no exception, which means the lock of $type is not set
+ // clean up
+ $view->unlockFile($path, $checkType);
+ return false;
+ } catch (\OCP\Lock\LockedException $e) {
+ // we could not acquire the counter-lock, which means
+ // the lock of $type was in place
+ return true;
+ }
+ }
}