Normalize path in View's lock methods

This commit is contained in:
Vincent Petry 2015-06-16 11:40:27 +02:00
parent e5d34a2733
commit 102c6ffc41
2 changed files with 27 additions and 4 deletions

View File

@ -1683,6 +1683,7 @@ class View {
*/
private function lockPath($path, $type) {
$absolutePath = $this->getAbsolutePath($path);
$absolutePath = Filesystem::normalizePath($absolutePath);
if (!$this->shouldLockFile($absolutePath)) {
return false;
}
@ -1717,6 +1718,7 @@ class View {
*/
public function changeLock($path, $type) {
$absolutePath = $this->getAbsolutePath($path);
$absolutePath = Filesystem::normalizePath($absolutePath);
if (!$this->shouldLockFile($absolutePath)) {
return false;
}
@ -1750,6 +1752,7 @@ class View {
*/
private function unlockPath($path, $type) {
$absolutePath = $this->getAbsolutePath($path);
$absolutePath = Filesystem::normalizePath($absolutePath);
if (!$this->shouldLockFile($absolutePath)) {
return false;
}
@ -1774,9 +1777,8 @@ class View {
* @return bool False if the path is excluded from locking, true otherwise
*/
public function lockFile($path, $type) {
$path = '/' . trim($path, '/');
$absolutePath = $this->getAbsolutePath($path);
$absolutePath = Filesystem::normalizePath($absolutePath);
if (!$this->shouldLockFile($absolutePath)) {
return false;
}
@ -1799,9 +1801,8 @@ class View {
* @return bool False if the path is excluded from locking, true otherwise
*/
public function unlockFile($path, $type) {
$path = rtrim($path, '/');
$absolutePath = $this->getAbsolutePath($path);
$absolutePath = Filesystem::normalizePath($absolutePath);
if (!$this->shouldLockFile($absolutePath)) {
return false;
}

View File

@ -1208,4 +1208,26 @@ class View extends \Test\TestCase {
$view = new \OC\Files\View();
$view->getPathRelativeToFiles($path);
}
public function testChangeLock() {
$view = new \OC\Files\View('/testuser/files/');
$storage = new Temporary(array());
\OC\Files\Filesystem::mount($storage, [], '/');
$view->lockFile('/test/sub', ILockingProvider::LOCK_SHARED);
$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
$view->changeLock('//test/sub', ILockingProvider::LOCK_EXCLUSIVE);
$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
$view->changeLock('test/sub', ILockingProvider::LOCK_SHARED);
$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
$view->unlockFile('/test/sub/', ILockingProvider::LOCK_SHARED);
$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
}
}