Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
reuse the cache entry we already have when doing rule checking
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and backportbot-nextcloud[bot] committed Sep 19, 2023
commit 91dbe875585d580fed360911ddab67a402c307be
2 changes: 1 addition & 1 deletion lib/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(ICache $cache, IStorage $storage, Operation $operati
protected function formatCacheEntry($entry) {
if (isset($entry['path']) && isset($entry['permissions'])) {
try {
$this->operation->checkFileAccess($this->storage, $entry['path'], $entry['mimetype'] === 'httpd/unix-directory');
$this->operation->checkFileAccess($this->storage, $entry['path'], $entry['mimetype'] === 'httpd/unix-directory', $entry);
} catch (ForbiddenException $e) {
$entry['permissions'] &= $this->mask;
}
Expand Down
39 changes: 31 additions & 8 deletions lib/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
namespace OCA\FilesAccessControl;

use Exception;
use OC\Files\FileInfo;
use OC\Files\Node\Folder;
use OC\Files\View;
use OCA\WorkflowEngine\Entity\File;
use OCP\EventDispatcher\Event;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\ForbiddenException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
Expand Down Expand Up @@ -69,9 +74,10 @@ public function __construct(
}

/**
* @param array|ICacheEntry|null $cacheEntry
* @throws ForbiddenException
*/
public function checkFileAccess(IStorage $storage, string $path, bool $isDir = false): void {
public function checkFileAccess(IStorage $storage, string $path, bool $isDir = false, $cacheEntry = null): void {
if (!$this->isBlockablePath($storage, $path) || $this->isCreatingSkeletonFiles() || $this->nestingLevel !== 0) {
// Allow creating skeletons and theming
// https://github.com/nextcloud/files_accesscontrol/issues/5
Expand All @@ -84,7 +90,7 @@ public function checkFileAccess(IStorage $storage, string $path, bool $isDir = f
$filePath = $this->translatePath($storage, $path);
$ruleMatcher = $this->manager->getRuleMatcher();
$ruleMatcher->setFileInfo($storage, $filePath, $isDir);
$node = $this->getNode($storage, $path);
$node = $this->getNode($storage, $path, $cacheEntry);
if ($node !== null) {
$ruleMatcher->setEntitySubject($this->fileEntity, $node);
}
Expand Down Expand Up @@ -280,16 +286,33 @@ public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatch
// Noop
}

private function getNode(IStorage $storage, string $path): ?Node {
/**
* @param array|ICacheEntry|null $cacheEntry
*/
private function getNode(IStorage $storage, string $path, $cacheEntry = null): ?Node {
/** @var IMountPoint|false $mountPoint */
$mountPoint = current($this->mountManager->findByStorageId($storage->getId()));
if ($mountPoint === false) {
if (!$mountPoint) {
return null;
}

$fullPath = $mountPoint->getMountPoint() . $path;
try {
return $this->rootFolder->get($fullPath);
} catch (NotFoundException $e) {
return null;
if ($cacheEntry) {
// todo: LazyNode?
$info = new FileInfo($fullPath, $mountPoint->getStorage(), $path, $cacheEntry, $mountPoint);
$isDir = $info->getType() === FileInfo::TYPE_FOLDER;
$view = new View('');
if ($isDir) {
return new Folder($this->rootFolder, $view, $path, $info);
} else {
return new \OC\Files\Node\File($this->rootFolder, $view, $path, $info);
}
} else {
try {
return $this->rootFolder->get($fullPath);
} catch (NotFoundException $e) {
return null;
}
}
}
}
1 change: 0 additions & 1 deletion lib/StorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use OCP\Files\Storage\IWriteStreamStorage;

class StorageWrapper extends Wrapper implements IWriteStreamStorage {

/** @var Operation */
protected $operation;

Expand Down