Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions apps/comments/lib/Search/CommentsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public function getOrder(string $route, array $routeParameters): int {
public function search(IUser $user, ISearchQuery $query): SearchResult {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());

if ($userFolder === null) {
return SearchResult::complete($this->l10n->t('Comments'), []);
}

$result = [];
$numComments = 50;
$offset = 0;
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
namespace OCA\DAV\Connector\Sabre;

use OC\Files\Mount\DummyMountPoint;
use OC\Files\Mount\MoveableMount;
use OC\Files\Storage\FailedStorage;
use OC\Files\View;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
Expand Down Expand Up @@ -106,9 +108,9 @@ public function createFile($name, $data = null) {
$info = $this->fileView->getFileInfo($this->path . '/' . $name);
if (!$info) {
// use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete
$info = new \OC\Files\FileInfo($path, null, null, [
$info = new \OC\Files\FileInfo($path, new FailedStorage(['exception' => new \LogicException('Dummy storage') ]), '', [
'type' => FileInfo::TYPE_FILE
], null);
], new DummyMountPoint());
}
$node = new File($this->fileView, $info);

Expand Down
12 changes: 2 additions & 10 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ class File extends Node implements IFile {

/**
* Sets up the node, expects a full path name
*
* @param View $view
* @param FileInfo $info
* @param ?\OCP\Share\IManager $shareManager
* @param ?IRequest $request
* @param ?IL10N $l10n
*/
public function __construct(View $view, FileInfo $info, ?IManager $shareManager = null, ?IRequest $request = null, ?IL10N $l10n = null) {
parent::__construct($view, $info, $shareManager);
Expand Down Expand Up @@ -368,7 +362,7 @@ public function put($data) {
if ($checksumHeader) {
$checksum = trim($checksumHeader);
$this->setChecksum($checksum);
} elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') {
} elseif ($this->getChecksum() !== '') {
$this->setChecksum('');
}
} catch (StorageNotAvailableException $e) {
Expand Down Expand Up @@ -605,10 +599,8 @@ private function convertToSabreException(\Exception $e) {

/**
* Get the checksum for this file
*
* @return string|null
*/
public function getChecksum() {
public function getChecksum(): string {
return $this->info->getChecksum();
}

Expand Down
6 changes: 3 additions & 3 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
if ($node instanceof File) {
//Add OC-Checksum header
$checksum = $node->getChecksum();
if ($checksum !== null && $checksum !== '') {
if ($checksum !== '') {
$response->addHeader('OC-Checksum', $checksum);
}
}
Expand Down Expand Up @@ -310,7 +310,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
});

$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) {
return $node->getInternalFileId();
return (string)$node->getInternalFileId();
});

$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) {
Expand Down Expand Up @@ -487,7 +487,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)

$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) {
$checksum = $node->getChecksum();
if ($checksum === null || $checksum === '') {
if ($checksum === '') {
return null;
}

Expand Down
32 changes: 8 additions & 24 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,20 @@
abstract class Node implements \Sabre\DAV\INode {
/**
* The path to the current node
*
* @var string
*/
protected $path;

protected FileInfo $info;

/**
* @var IManager
*/
protected $shareManager;

protected string $path = '';
protected \OCP\Files\Node $node;

/**
* Sets up the node, expects a full path name
*/
public function __construct(
protected View $fileView,
FileInfo $info,
?IManager $shareManager = null,
protected FileInfo $info,
protected ?IManager $shareManager = null,
) {
$this->path = $this->fileView->getRelativePath($info->getPath());
$this->info = $info;
if ($shareManager) {
$this->shareManager = $shareManager;
} else {
if (!$this->shareManager) {
$this->shareManager = Server::get(\OCP\Share\IManager::class);
}
if ($info instanceof Folder || $info instanceof File) {
Expand Down Expand Up @@ -141,7 +128,7 @@ public function setName($name) {
public function getLastModified() {
$timestamp = $this->info->getMtime();
if (!empty($timestamp)) {
return (int)$timestamp;
return $timestamp;
}
return $timestamp;
}
Expand Down Expand Up @@ -207,7 +194,7 @@ public function getSize(): int|float {
* @return int
*/
public function getId() {
return $this->info->getId();
return $this->info->getId() ?? -1;
}

/**
Expand All @@ -221,11 +208,8 @@ public function getFileId() {
return null;
}

/**
* @return integer
*/
public function getInternalFileId() {
return $this->info->getId();
public function getInternalFileId(): int {
return $this->info->getId() ?? -1;
}

public function getInternalPath(): string {
Expand Down
25 changes: 18 additions & 7 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\Files\ForbiddenException;
use OCP\Files\InvalidPathException;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException;
use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
Expand Down Expand Up @@ -68,6 +69,8 @@ protected function setUp(): void {
parent::setUp();

$this->view = $this->createMock(View::class);
$this->view->method('getAbsolutePath')->willReturnArgument(0);

$this->info = $this->createMock(FileInfo::class);
$this->info->method('isReadable')
->willReturn(true);
Expand Down Expand Up @@ -102,7 +105,7 @@ public function testDeleteRootFolderFails(): void {
->willReturn(true);
$this->view->expects($this->never())
->method('rmdir');
$dir = $this->getDir();
$dir = $this->getDir('/');
$dir->delete();
}

Expand Down Expand Up @@ -226,6 +229,8 @@ public function testGetChildrenNoPermission(): void {
->method('isReadable')
->willReturn(false);

$this->view->method('getRelativePath')->willReturnArgument(0);

$dir = new Directory($this->view, $info);
$dir->getChildren();
}
Expand All @@ -238,6 +243,8 @@ public function testGetChildNoPermission(): void {
->method('isReadable')
->willReturn(false);

$this->view->method('getRelativePath')->willReturnArgument(0);

$dir = new Directory($this->view, $this->info);
$dir->getChild('test');
}
Expand All @@ -250,6 +257,8 @@ public function testGetChildThrowStorageNotAvailableException(): void {
->method('getFileInfo')
->willThrowException(new StorageNotAvailableException());

$this->view->method('getRelativePath')->willReturnArgument(0);

$dir = new Directory($this->view, $this->info);
$dir->getChild('.');
}
Expand All @@ -264,6 +273,8 @@ public function testGetChildThrowInvalidPath(): void {
$this->view->expects($this->never())
->method('getFileInfo');

$this->view->method('getRelativePath')->willReturnArgument(0);

$dir = new Directory($this->view, $this->info);
$dir->getChild('.');
}
Expand Down Expand Up @@ -421,12 +432,12 @@ public static function moveSuccessProvider(): array {
private function moveTest(string $source, string $destination, array $updatables, array $deletables): void {
$view = new TestViewDirectory($updatables, $deletables);

$sourceInfo = new FileInfo($source, null, null, [
$sourceInfo = new FileInfo($source, $this->createMock(IStorage::class), '', [
'type' => FileInfo::TYPE_FOLDER,
], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [
], $this->createMock(IMountPoint::class));
$targetInfo = new FileInfo(dirname($destination), $this->createMock(IStorage::class), '', [
'type' => FileInfo::TYPE_FOLDER,
], null);
], $this->createMock(IMountPoint::class));

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
Expand All @@ -451,8 +462,8 @@ public function testFailingMove(): void {

$view = new TestViewDirectory($updatables, $deletables);

$sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null);
$targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null);
$sourceInfo = new FileInfo($source, $this->createMock(IStorage::class), '', ['type' => FileInfo::TYPE_FOLDER], $this->createMock(IMountPoint::class));
$targetInfo = new FileInfo(dirname($destination), $this->createMock(IStorage::class), '', ['type' => FileInfo::TYPE_FOLDER], $this->createMock(IMountPoint::class));

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
Expand Down
Loading
Loading