Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lib/private/Files/Node/LazyRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
*/
namespace OC\Files\Node;

use OCP\Files\Cache\ICacheEntry;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node as INode;

/**
* Class LazyRoot
Expand Down Expand Up @@ -52,4 +55,8 @@ public function getUserFolder($userId) {
public function getByIdInPath(int $id, string $path) {
return $this->__call(__FUNCTION__, func_get_args());
}

public function getNodeFromCacheEntryAndMount(ICacheEntry $cacheEntry, IMountPoint $mountPoint): INode {
return $this->getRootFolder()->getNodeFromCacheEntryAndMount($cacheEntry, $mountPoint);
}
}
2 changes: 1 addition & 1 deletion lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Node implements INode {
* @param string $path
* @param FileInfo $fileInfo
*/
public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?Node $parent = null, bool $infoHasSubMountsIncluded = true) {
public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?INode $parent = null, bool $infoHasSubMountsIncluded = true) {
if (Filesystem::normalizePath($view->getRoot()) !== '/') {
throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
}
Expand Down
26 changes: 26 additions & 0 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OC\Hooks\PublicEmitter;
use OC\User\NoUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -487,4 +488,29 @@ public function getByIdInPath(int $id, string $path): array {
});
return $folders;
}

public function getNodeFromCacheEntryAndMount(ICacheEntry $cacheEntry, IMountPoint $mountPoint): INode {
$path = $cacheEntry->getPath();
$fullPath = $mountPoint->getMountPoint() . $path;
// todo: LazyNode?
$info = new FileInfo($fullPath, $mountPoint->getStorage(), $path, $cacheEntry, $mountPoint);
$parentPath = dirname($fullPath);
$parent = new LazyFolder($this, function () use ($parentPath) {
$parent = $this->get($parentPath);
if ($parent instanceof \OCP\Files\Folder) {
return $parent;
} else {
throw new \Exception("parent $parentPath is not a folder");
}
}, [
'path' => $parentPath,
]);
$isDir = $info->getType() === FileInfo::TYPE_FOLDER;
$view = new View('');
if ($isDir) {
return new Folder($this, $view, $path, $info, $parent);
} else {
return new File($this, $view, $path, $info, $parent);
}
}
}
12 changes: 12 additions & 0 deletions lib/public/Files/IRootFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

use OC\Hooks\Emitter;
use OC\User\NoUserException;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node as INode;

/**
* Interface IRootFolder
Expand Down Expand Up @@ -64,6 +66,16 @@ public function getByIdInPath(int $id, string $path);
*/
public function getMountsIn(string $mountPoint): array;

/**
* Create a `Node` for a file or folder from the cache entry and mountpoint
*
* @param ICacheEntry $cacheEntry
* @param IMountPoint $mountPoint
* @return Node
* @since 28.0.0
*/
public function getNodeFromCacheEntryAndMount(ICacheEntry $cacheEntry, IMountPoint $mountPoint): INode;

/**
* @since 28.0.0
*/
Expand Down