Skip to content

Commit

Permalink
fixup! Do not set up filesystem on every call
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Feb 7, 2023
1 parent 6296dc4 commit a0a28a9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 124 deletions.
14 changes: 0 additions & 14 deletions apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ public function nodeForPathProvider() {
'regulardir',
'dir'
],
// file with chunky file name
[
'regularfile.txt-chunking-123566789-10-1',
'regularfile.txt',
'regularfile.txt',
'file'
],
// regular file in subdir
[
'subdir/regularfile.txt',
Expand All @@ -239,13 +232,6 @@ public function nodeForPathProvider() {
'regulardir',
'dir'
],
// file with chunky file name in subdir
[
'subdir/regularfile.txt-chunking-123566789-10-1',
'subdir/regularfile.txt',
'regularfile.txt',
'file'
],
];
}

Expand Down
110 changes: 0 additions & 110 deletions apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,114 +92,4 @@ public function testUploadOverWriteWriteLocked(): void {
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}

public function testChunkedUpload(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');

$this->assertFalse($view->file_exists('foo.txt'));
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);

$this->assertEquals(201, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));

$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);

$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertTrue($view->file_exists('foo.txt'));

$this->assertEquals('asdbar', $view->file_get_contents('foo.txt'));

$info = $view->getFileInfo('foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
$this->assertEquals(6, $info->getSize());
}

public function testChunkedUploadOverWrite(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');

$view->file_put_contents('foo.txt', 'bar');
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);

$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertEquals('bar', $view->file_get_contents('foo.txt'));

$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);

$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());

$this->assertEquals('asdbar', $view->file_get_contents('foo.txt'));

$info = $view->getFileInfo('foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
$this->assertEquals(6, $info->getSize());
}

public function testChunkedUploadOutOfOrder(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');

$this->assertFalse($view->file_exists('foo.txt'));
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);

$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));

$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);

$this->assertEquals(201, $response->getStatus());
$this->assertTrue($view->file_exists('foo.txt'));

$this->assertEquals('asdbar', $view->file_get_contents('foo.txt'));

$info = $view->getFileInfo('foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
$this->assertEquals(6, $info->getSize());
}

public function testChunkedUploadOutOfOrderReadLocked(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');

$this->assertFalse($view->file_exists('foo.txt'));

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

try {
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
} catch (\OCA\DAV\Connector\Sabre\Exception\FileLocked $e) {
$this->fail('Didn\'t expect locked error for the first chunk on read lock');
return;
}

$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));

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

public function testChunkedUploadOutOfOrderWriteLocked(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');

$this->assertFalse($view->file_exists('foo.txt'));

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

try {
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
} catch (\OCA\DAV\Connector\Sabre\Exception\FileLocked $e) {
$this->fail('Didn\'t expect locked error for the first chunk on write lock'); // maybe forbid this in the future for write locks only?
return;
}

$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));

// last chunk should trigger the locked error since it tries to assemble
$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 a0a28a9

Please sign in to comment.