summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-11 16:11:16 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-06-12 11:09:38 +0200
commitcaf16b083e3abaea18a05fe5f923bd306c09ac6b (patch)
treebfa53512a008bd4f0f79efff5c21cb9ac5e4485e /lib
parentcda9685c0ece25fe99a8046a94f06f145191a09d (diff)
downloadnextcloud-server-caf16b083e3abaea18a05fe5f923bd306c09ac6b.tar.gz
nextcloud-server-caf16b083e3abaea18a05fe5f923bd306c09ac6b.zip
Only lock files in data/username/files/
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/view.php62
1 files changed, 53 insertions, 9 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index b98842f5eb7..7bb4a2b4f78 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1663,12 +1663,15 @@ class View {
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
*/
private function lockPath($path, $type) {
+ $absolutePath = $this->getAbsolutePath($path);
+ if (!$this->shouldLockFile($absolutePath)) {
+ return;
+ }
+
$mount = $this->getMount($path);
if ($mount) {
$mount->getStorage()->acquireLock(
- $mount->getInternalPath(
- $this->getAbsolutePath($path)
- ),
+ $mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
@@ -1680,12 +1683,15 @@ class View {
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
*/
private function changeLock($path, $type) {
+ $absolutePath = $this->getAbsolutePath($path);
+ if (!$this->shouldLockFile($absolutePath)) {
+ return;
+ }
+
$mount = $this->getMount($path);
if ($mount) {
$mount->getStorage()->changeLock(
- $mount->getInternalPath(
- $this->getAbsolutePath($path)
- ),
+ $mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
@@ -1697,12 +1703,15 @@ class View {
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
*/
private function unlockPath($path, $type) {
+ $absolutePath = $this->getAbsolutePath($path);
+ if (!$this->shouldLockFile($absolutePath)) {
+ return;
+ }
+
$mount = $this->getMount($path);
if ($mount) {
$mount->getStorage()->releaseLock(
- $mount->getInternalPath(
- $this->getAbsolutePath($path)
- ),
+ $mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
@@ -1717,6 +1726,12 @@ class View {
*/
public function lockFile($path, $type) {
$path = '/' . trim($path, '/');
+
+ $absolutePath = $this->getAbsolutePath($path);
+ if (!$this->shouldLockFile($absolutePath)) {
+ return;
+ }
+
$this->lockPath($path, $type);
$parents = $this->getParents($path);
@@ -1733,6 +1748,12 @@ class View {
*/
public function unlockFile($path, $type) {
$path = rtrim($path, '/');
+
+ $absolutePath = $this->getAbsolutePath($path);
+ if (!$this->shouldLockFile($absolutePath)) {
+ return;
+ }
+
$this->unlockPath($path, $type);
$parents = $this->getParents($path);
@@ -1740,4 +1761,27 @@ class View {
$this->unlockPath($parent, ILockingProvider::LOCK_SHARED);
}
}
+
+ /**
+ * Only lock files in data/user/files/
+ *
+ * @param string $path Absolute path to the file/folder we try to (un)lock
+ * @return bool
+ */
+ protected function shouldLockFile($path) {
+ $path = Filesystem::normalizePath($path);
+
+ if (substr_count($path, '/') >= 3) {
+ // E.g.: /username/files/path-to-file
+ $pathSegments = explode('/', $path, 4);
+ return $pathSegments[2] === 'files';
+
+ } else if (substr_count($path, '/') === 2) {
+ // E.g.: /username/files
+ $pathSegments = explode('/', $path, 3);
+ return $pathSegments[2] === 'files';
+ }
+
+ return true;
+ }
}