namespace OC\DirectEditing;
use Doctrine\DBAL\FetchMode;
+use OC\Files\Node\Folder;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
if ($userFolder->nodeExists($path)) {
throw new \RuntimeException('File already exists');
} else {
- $file = $userFolder->newFile($path);
+ if (!$userFolder->nodeExists(dirname($path))) {
+ throw new \RuntimeException('Invalid path');
+ }
+ /** @var Folder $folder */
+ $folder = $userFolder->get(dirname($path));
+ $file = $folder->newFile(basename($path));
$editor = $this->getEditor($editorId);
$creators = $editor->getCreators();
foreach ($creators as $creator) {
} catch (NotFoundException $e) {
}
try {
- $targetFile = $userFolder->newFile($filePath);
+ if (!$userFolder->nodeExists(dirname($filePath))) {
+ throw new GenericFileException($this->l10n->t('Invalid path'));
+ }
+ $folder = $userFolder->get(dirname($filePath));
+ $targetFile = $folder->newFile(basename($filePath));
if ($templateType === 'user' && $templateId !== '') {
$template = $userFolder->get($templateId);
$template->copy($targetFile->getPath());
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
+ $folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->with('/File.txt')
- ->willReturn(false);
- $this->userFolder->expects($this->once())
+ ->withConsecutive(['/File.txt'], ['/'])
+ ->willReturnOnConsecutiveCalls(false, true);
+ $this->userFolder
+ ->method('get')
+ ->with('/')
+ ->willReturn($folder);
+ $folder->expects($this->once())
->method('newFile')
->willReturn($file);
$token = $this->manager->create('/File.txt', 'testeditor', 'createEmpty');
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
+ $folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->with('/File.txt')
- ->willReturn(false);
- $this->userFolder->expects($this->once())
+ ->withConsecutive(['/File.txt'], ['/'])
+ ->willReturnOnConsecutiveCalls(false, true);
+ $this->userFolder
+ ->method('get')
+ ->with('/')
+ ->willReturn($folder);
+ $folder->expects($this->once())
->method('newFile')
->willReturn($file);
$this->manager->create('/File.txt', 'testeditor', 'createEmpty');