Skip to content

Commit 35a916e

Browse files
authored
Merge pull request #4829 from nextcloud/fix/secure-view-new-file
fix: Avoid failing on fopen for NonExistingFiles
2 parents 31c8db6 + 07dc03b commit 35a916e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/Storage/SecureViewWrapper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\Files\Folder;
1515
use OCP\Files\ForbiddenException;
1616
use OCP\Files\IRootFolder;
17+
use OCP\Files\NotFoundException;
1718
use OCP\Files\Storage\ISharedStorage;
1819
use OCP\Files\Storage\IStorage;
1920
use OCP\IUserSession;
@@ -93,7 +94,12 @@ private function shouldSecure(string $path, ?IStorage $sourceStorage = null): bo
9394

9495
$isSharedStorage = $storage->instanceOfStorage(ISharedStorage::class);
9596
$mountNode = $this->rootFolder->get($storage->getMountPoint());
96-
$node = $mountNode instanceof Folder ? $mountNode->get($path) : $mountNode;
97+
try {
98+
$node = $mountNode instanceof Folder ? $mountNode->get($path) : $mountNode;
99+
} catch (NotFoundException $e) {
100+
// If the file is just created we may need to check the parent as this is only just about figuring out if it is a share
101+
$node = $mountNode->get(dirname($path));
102+
}
97103
$share = $isSharedStorage ? $node->getStorage()->getShare() : null;
98104
$userId = $this->userSession->getUser()?->getUID();
99105

0 commit comments

Comments
 (0)