Skip to content

Commit

Permalink
Merge pull request #12300 from nextcloud/backport/12230/stable14
Browse files Browse the repository at this point in the history
[14]  Do not log FileLock as exception
  • Loading branch information
MorrisJobke authored Nov 6, 2018
2 parents e10b7c8 + 9386a0c commit 8a86f59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
3 changes: 3 additions & 0 deletions apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\DAV\Connector\Sabre;

use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCP\Files\StorageNotAvailableException;
use OCP\ILogger;
Expand Down Expand Up @@ -69,6 +70,8 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
// happens when a certain method is not allowed to be called
// for example creating a folder that already exists
MethodNotAllowed::class => true,
// A locked file is perfectly valid and can happen in various cases
FileLocked::class => true,
];

/** @var string */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public function testDownload() {
$this->assertEquals(stream_get_contents($response->getBody()), 'bar');
}

/**
* @expectedException \OCA\DAV\Connector\Sabre\Exception\FileLocked
*/
public function testDownloadWriteLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
Expand All @@ -57,7 +54,8 @@ public function testDownloadWriteLocked() {

$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);

$this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
$result = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}

public function testDownloadReadLocked() {
Expand Down
24 changes: 8 additions & 16 deletions apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function testUploadOverWrite() {
$this->assertEquals(3, $info->getSize());
}

/**
* @expectedException \OCA\DAV\Connector\Sabre\Exception\FileLocked
*/
public function testUploadOverWriteReadLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
Expand All @@ -79,12 +76,10 @@ public function testUploadOverWriteReadLocked() {

$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);

$this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}

/**
* @expectedException \OCA\DAV\Connector\Sabre\Exception\FileLocked
*/
public function testUploadOverWriteWriteLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
Expand All @@ -94,7 +89,8 @@ public function testUploadOverWriteWriteLocked() {

$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);

$this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}

public function testChunkedUpload() {
Expand Down Expand Up @@ -162,9 +158,6 @@ public function testChunkedUploadOutOfOrder() {
$this->assertEquals(6, $info->getSize());
}

/**
* @expectedException \OCA\DAV\Connector\Sabre\Exception\FileLocked
*/
public function testChunkedUploadOutOfOrderReadLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
Expand All @@ -184,12 +177,10 @@ public function testChunkedUploadOutOfOrderReadLocked() {
$this->assertFalse($view->file_exists('foo.txt'));

// last chunk should trigger the locked error since it tries to assemble
$this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}

/**
* @expectedException \OCA\DAV\Connector\Sabre\Exception\FileLocked
*/
public function testChunkedUploadOutOfOrderWriteLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
Expand All @@ -209,6 +200,7 @@ public function testChunkedUploadOutOfOrderWriteLocked() {
$this->assertFalse($view->file_exists('foo.txt'));

// last chunk should trigger the locked error since it tries to assemble
$this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}
}

0 comments on commit 8a86f59

Please sign in to comment.