summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Node/Folder.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Node/Folder.php')
-rw-r--r--lib/private/Files/Node/Folder.php58
1 files changed, 49 insertions, 9 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 19f04048779..4a134cdcdbf 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -156,14 +156,12 @@ class Folder extends Node implements \OCP\Files\Folder {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
$fullPath = $this->getFullPath($path);
$nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath);
- $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
- $this->root->emit('\OC\Files', 'preCreate', array($nonExisting));
+ $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
if(!$this->view->mkdir($fullPath)) {
throw new NotPermittedException('Could not create folder');
}
$node = new Folder($this->root, $this->view, $fullPath);
- $this->root->emit('\OC\Files', 'postWrite', array($node));
- $this->root->emit('\OC\Files', 'postCreate', array($node));
+ $this->sendHooks(['postWrite', 'postCreate'], [$node]);
return $node;
} else {
throw new NotPermittedException('No create permission for folder');
@@ -179,14 +177,12 @@ class Folder extends Node implements \OCP\Files\Folder {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
$fullPath = $this->getFullPath($path);
$nonExisting = new NonExistingFile($this->root, $this->view, $fullPath);
- $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
- $this->root->emit('\OC\Files', 'preCreate', array($nonExisting));
+ $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
if (!$this->view->touch($fullPath)) {
throw new NotPermittedException('Could not create path');
}
$node = new File($this->root, $this->view, $fullPath);
- $this->root->emit('\OC\Files', 'postWrite', array($node));
- $this->root->emit('\OC\Files', 'postCreate', array($node));
+ $this->sendHooks(['postWrite', 'postCreate'], [$node]);
return $node;
}
throw new NotPermittedException('No create permission for path');
@@ -303,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 [];
}
@@ -331,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);
}
@@ -341,7 +381,7 @@ class Folder extends Node implements \OCP\Files\Folder {
$fileInfo = $this->getFileInfo();
$this->view->rmdir($this->path);
$nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo);
- $this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
+ $this->sendHooks(['postDelete'], [$nonExisting]);
$this->exists = false;
} else {
throw new NotPermittedException('No delete permission for path');