Properly handle creating the template directory in a subfolder (fixes #25787)

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2021-03-31 16:21:40 +02:00 committed by backportbot[bot]
parent 89a19a338e
commit dc8e819915
1 changed files with 3 additions and 3 deletions

View File

@ -36,7 +36,6 @@ use OCP\Files\GenericFileException;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Template\FileCreatedFromTemplateEvent; use OCP\Files\Template\FileCreatedFromTemplateEvent;
use OCP\Files\Template\ICustomTemplateProvider; use OCP\Files\Template\ICustomTemplateProvider;
use OCP\Files\Template\ITemplateManager; use OCP\Files\Template\ITemplateManager;
@ -299,9 +298,10 @@ class TemplateManager implements ITemplateManager {
} }
try { try {
$folder = $userFolder->newFolder($userTemplatePath);
} catch (NotPermittedException $e) {
$folder = $userFolder->get($userTemplatePath); $folder = $userFolder->get($userTemplatePath);
} catch (NotFoundException $e) {
$folder = $userFolder->get(dirname($userTemplatePath));
$folder = $folder->newFolder(basename($userTemplatePath));
} }
$folderIsEmpty = count($folder->getDirectoryListing()) === 0; $folderIsEmpty = count($folder->getDirectoryListing()) === 0;