Fix getById for files in appdata and the root mount

In case the path we are currently in is inside the appdata_* folder,
the original getById method does not work, because it can only look inside
the user's mount points. But the user has no mount point for the root storage.

So in that case we directly check the mount of the root if it contains
the id. If it does we check if the path is inside the path we are working
in.

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-09-17 11:15:59 +02:00
parent d43a478840
commit a4ba2113b2
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 44 additions and 0 deletions

View File

@ -299,6 +299,9 @@ class Folder extends Node implements \OCP\Files\Folder {
}));
if (count($mountsContainingFile) === 0) {
if ($user === $this->getAppDataDirectoryName()) {
return $this->getByIdInRootMount((int) $id);
}
return [];
}
@ -327,6 +330,47 @@ class Folder extends Node implements \OCP\Files\Folder {
});
}
protected function getAppDataDirectoryName(): string {
$instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid');
return 'appdata_' . $instanceId;
}
/**
* In case the path we are currently in is inside the appdata_* folder,
* the original getById method does not work, because it can only look inside
* the user's mount points. But the user has no mount point for the root storage.
*
* So in that case we directly check the mount of the root if it contains
* the id. If it does we check if the path is inside the path we are working
* in.
*
* @param int $id
* @return array
*/
protected function getByIdInRootMount(int $id): array {
$mount = $this->root->getMount('');
$cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
if (!$cacheEntry) {
return [];
}
$absolutePath = '/' . ltrim($cacheEntry->getPath(), '/');
$currentPath = rtrim($this->path, '/') . '/';
if (strpos($absolutePath, $currentPath) !== 0) {
return [];
}
return [$this->root->createNode(
$absolutePath, new \OC\Files\FileInfo(
$absolutePath,
$mount->getStorage(),
$cacheEntry->getPath(),
$cacheEntry,
$mount
))];
}
public function getFreeSpace() {
return $this->view->free_space($this->path);
}