Skip to content
Closed
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
Add hidden user folder
this can be used by apps to have apps that are within the users home
folder but are hidden from the normal ui bits

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Jan 27, 2023
commit 20772c28f56d4ea6ebd39f511fcaf71b24bbb821
8 changes: 6 additions & 2 deletions apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,14 @@ public function getChildren() {
throw new Locked();
}

$hiddenName = 'hidden_' . \OC_Util::getInstanceId();

$nodes = [];
foreach ($folderContent as $info) {
$node = $this->getChild($info->getName(), $info);
$nodes[] = $node;
if ($info->getName() !== $hiddenName) {
$node = $this->getChild($info->getName(), $info);
$nodes[] = $node;
}
}
$this->dirContent = $nodes;
return $this->dirContent;
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
$query->andWhere($searchExpr);
}

// exclude entries from the hidden folder in the user storage
$query->andWhere($query->expr()->notLike('path', $query->createNamedParameter('files/hidden_' . \OC_Util::getInstanceId() . '%')));

$this->searchBuilder->addSearchOrdersToQuery($query, $searchQuery->getOrder());

if ($searchQuery->getLimit()) {
Expand Down
6 changes: 6 additions & 0 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,14 @@ public function search($query) {
$mountByMountPoint = ['' => $mount];

if (!$limitToHome) {
$hiddenFolder = 'hidden_' . \OC_Util::getInstanceId();
$mounts = $this->root->getMountsIn($this->path);
foreach ($mounts as $mount) {
// don't search in mounts inside the hidden folder
if (strpos($mount->getMountPoint(), '/' . $hiddenFolder .'/') !== false) {
continue;
}

$storage = $mount->getStorage();
if ($storage) {
$relativeMountPoint = ltrim(substr($mount->getMountPoint(), $rootLength), '/');
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Node/LazyRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public function getUserFolder($userId) {
public function getByIdInPath(int $id, string $path) {
return $this->__call(__FUNCTION__, func_get_args());
}

public function getHiddenUserFolder($userId) {
return $this->__call(__FUNCTION__, func_get_args());
}
}
14 changes: 14 additions & 0 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ public function getUserFolder($userId) {
return $this->userFolderCache->get($userId);
}

public function getHiddenUserFolder($userId) {
$userFolder = $this->getUserFolder($userId);
$hiddenName = 'hidden_' . \OC_Util::getInstanceId();
try {
return $userFolder->get($hiddenName);
} catch (NotFoundException $e) {
return $userFolder->newFolder($hiddenName);
}
}

public function clearCache() {
$this->userFolderCache = new CappedMemoryCache();
}

public function getUserMountCache() {
return $this->userMountCache;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1665,9 +1665,16 @@ private function searchCommon($method, $args) {
}
}

$hiddenFolder = 'hidden_' . \OC_Util::getInstanceId();
$mounts = Filesystem::getMountManager()->findIn($this->fakeRoot);
foreach ($mounts as $mount) {
$mountPoint = $mount->getMountPoint();

// don't search in mounts inside the hidden folder
if (strpos($mountPoint, '/' . $hiddenFolder .'/') !== false) {
continue;
}

$storage = $mount->getStorage();
if ($storage) {
$cache = $storage->getCache('');
Expand Down
18 changes: 18 additions & 0 deletions lib/public/Files/IRootFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,22 @@ public function getUserFolder($userId);
* @since 24.0.0
*/
public function getByIdInPath(int $id, string $path);

/**
* Returns a hidden files directory
*
* This directory can be used to place files hidden for user,
* but still usable through most normal api as it is still inside the user folder
*
* Note that an experienced user can still browser this folder if they manually navigate into it.
* Do not rely on it being hidden for security purposes
*
* @param string $userId user ID
* @return \OCP\Files\Folder
* @throws NoUserException
* @throws NotPermittedException
*
* @since 24.0.0
*/
public function getHiddenUserFolder($userId);
}