// If no token is sent along, rely on login only
$allowedPermissions = OCP\PERMISSION_ALL;
+$errorCode = null;
$l = OC_L10N::get('files');
if (empty($_POST['dirToken'])) {
$meta = \OC\Files\Filesystem::getFileInfo($target);
if ($meta === false) {
- $error = $l->t('Upload failed. Could not get file info.');
+ $error = $l->t('The target folder has been moved or deleted.');
+ $errorCode = 'targetnotfound';
} else {
$result[] = array('status' => 'success',
'mime' => $meta['mimetype'],
OCP\JSON::encodedPrint($result);
exit();
} else {
- OCP\JSON::error(array(array('data' => array_merge(array('message' => $error), $storageStats))));
+ OCP\JSON::error(array(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats))));
}
$result['data'] = array(
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved.")
);
+ // rename to non-existing folder is denied
+ } else if (!$this->view->file_exists($dir)) {
+ $result['data'] = array('message' => (string)$this->l10n->t(
+ 'The target folder has been moved or deleted.',
+ array($dir)),
+ 'code' => 'targetnotfound'
+ );
// rename to existing file is denied
} else if ($this->view->file_exists($dir . '/' . $newname)) {
$l10nMock->expects($this->any())
->method('t')
->will($this->returnArgument(0));
- $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath', 'getFileInfo'), array(), '', false);
+ $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath', 'getFileInfo', 'file_exists'), array(), '', false);
$viewMock->expects($this->any())
->method('normalizePath')
->will($this->returnArgument(0));
$oldname = 'Shared';
$newname = 'new_name';
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/')
+ ->will($this->returnValue(true));
+
$result = $this->files->rename($dir, $oldname, $newname);
$expected = array(
'success' => false,
$oldname = 'Shared';
$newname = 'new_name';
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/test')
+ ->will($this->returnValue(true));
+
$this->viewMock->expects($this->any())
->method('getFileInfo')
->will($this->returnValue(array(
$oldname = 'oldname';
$newname = 'newname';
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/')
+ ->will($this->returnValue(true));
+
$this->viewMock->expects($this->any())
->method('getFileInfo')
->will($this->returnValue(array(
'name' => 'new_name',
)));
-
$result = $this->files->rename($dir, $oldname, $newname);
$this->assertTrue($result['success']);
$this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']);
$this->assertFalse($result['data']['isPreviewAvailable']);
}
+
+ /**
+ * Test rename inside a folder that doesn't exist any more
+ */
+ function testRenameInNonExistingFolder() {
+ $dir = '/unexist';
+ $oldname = 'oldname';
+ $newname = 'newname';
+
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/unexist')
+ ->will($this->returnValue(false));
+
+ $this->viewMock->expects($this->any())
+ ->method('getFileInfo')
+ ->will($this->returnValue(array(
+ 'fileid' => 123,
+ 'type' => 'dir',
+ 'mimetype' => 'httpd/unix-directory',
+ 'size' => 18,
+ 'etag' => 'abcdef',
+ 'directory' => '/unexist',
+ 'name' => 'new_name',
+ )));
+
+ $result = $this->files->rename($dir, $oldname, $newname);
+
+ $this->assertFalse($result['success']);
+ $this->assertEquals('targetnotfound', $result['data']['code']);
+ }
}