Added error message for when target folder was removed
Whent trying to upload/rename/create files in a folder that was removed or rename, the correct error message is now shown. In the case of upload of multiple files, the upload is cancelled. This situation can happen if the target folder was renamed or removed from another browser window or client.
This commit is contained in:
parent
a2b79ead2d
commit
58c7042e70
6 changed files with 83 additions and 4 deletions
|
@ -64,6 +64,15 @@ if(strpos($filename, '/') !== false) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
|
||||||
|
$result['data'] = array('message' => (string)$l10n->t(
|
||||||
|
'The target folder has been moved or deleted.'),
|
||||||
|
'code' => 'targetnotfound'
|
||||||
|
);
|
||||||
|
OCP\JSON::error($result);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
//TODO why is stripslashes used on foldername in newfolder.php but not here?
|
//TODO why is stripslashes used on foldername in newfolder.php but not here?
|
||||||
$target = $dir.'/'.$filename;
|
$target = $dir.'/'.$filename;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,15 @@ if(strpos($foldername, '/') !== false) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
|
||||||
|
$result['data'] = array('message' => (string)$l10n->t(
|
||||||
|
'The target folder has been moved or deleted.'),
|
||||||
|
'code' => 'targetnotfound'
|
||||||
|
);
|
||||||
|
OCP\JSON::error($result);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
//TODO why is stripslashes used on foldername here but not in newfile.php?
|
//TODO why is stripslashes used on foldername here but not in newfile.php?
|
||||||
$target = $dir . '/' . stripslashes($foldername);
|
$target = $dir . '/' . stripslashes($foldername);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ OCP\JSON::setContentTypeHeader('text/plain');
|
||||||
// If no token is sent along, rely on login only
|
// If no token is sent along, rely on login only
|
||||||
|
|
||||||
$allowedPermissions = OCP\PERMISSION_ALL;
|
$allowedPermissions = OCP\PERMISSION_ALL;
|
||||||
|
$errorCode = null;
|
||||||
|
|
||||||
$l = OC_L10N::get('files');
|
$l = OC_L10N::get('files');
|
||||||
if (empty($_POST['dirToken'])) {
|
if (empty($_POST['dirToken'])) {
|
||||||
|
@ -125,7 +126,8 @@ if (strpos($dir, '..') === false) {
|
||||||
|
|
||||||
$meta = \OC\Files\Filesystem::getFileInfo($target);
|
$meta = \OC\Files\Filesystem::getFileInfo($target);
|
||||||
if ($meta === false) {
|
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 {
|
} else {
|
||||||
$result[] = array('status' => 'success',
|
$result[] = array('status' => 'success',
|
||||||
'mime' => $meta['mimetype'],
|
'mime' => $meta['mimetype'],
|
||||||
|
@ -177,5 +179,5 @@ if ($error === false) {
|
||||||
OCP\JSON::encodedPrint($result);
|
OCP\JSON::encodedPrint($result);
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} 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))));
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,6 +315,13 @@ $(document).ready(function() {
|
||||||
} else {
|
} else {
|
||||||
// HTTP connection problem
|
// HTTP connection problem
|
||||||
OC.Notification.show(data.errorThrown);
|
OC.Notification.show(data.errorThrown);
|
||||||
|
if (data.result) {
|
||||||
|
var result = JSON.parse(data.result);
|
||||||
|
if (result && result[0] && result[0].data && result[0].data.code === 'targetnotfound') {
|
||||||
|
// abort upload of next files if any
|
||||||
|
OC.Upload.cancelUploads();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//hide notification after 10 sec
|
//hide notification after 10 sec
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|
|
@ -59,6 +59,13 @@ class App {
|
||||||
$result['data'] = array(
|
$result['data'] = array(
|
||||||
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved.")
|
'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
|
// rename to existing file is denied
|
||||||
} else if ($this->view->file_exists($dir . '/' . $newname)) {
|
} else if ($this->view->file_exists($dir . '/' . $newname)) {
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$l10nMock->expects($this->any())
|
$l10nMock->expects($this->any())
|
||||||
->method('t')
|
->method('t')
|
||||||
->will($this->returnArgument(0));
|
->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())
|
$viewMock->expects($this->any())
|
||||||
->method('normalizePath')
|
->method('normalizePath')
|
||||||
->will($this->returnArgument(0));
|
->will($this->returnArgument(0));
|
||||||
|
@ -63,6 +63,11 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$oldname = 'Shared';
|
$oldname = 'Shared';
|
||||||
$newname = 'new_name';
|
$newname = 'new_name';
|
||||||
|
|
||||||
|
$this->viewMock->expects($this->at(0))
|
||||||
|
->method('file_exists')
|
||||||
|
->with('/')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$result = $this->files->rename($dir, $oldname, $newname);
|
$result = $this->files->rename($dir, $oldname, $newname);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
@ -80,6 +85,11 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$oldname = 'Shared';
|
$oldname = 'Shared';
|
||||||
$newname = 'new_name';
|
$newname = 'new_name';
|
||||||
|
|
||||||
|
$this->viewMock->expects($this->at(0))
|
||||||
|
->method('file_exists')
|
||||||
|
->with('/test')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->viewMock->expects($this->any())
|
$this->viewMock->expects($this->any())
|
||||||
->method('getFileInfo')
|
->method('getFileInfo')
|
||||||
->will($this->returnValue(array(
|
->will($this->returnValue(array(
|
||||||
|
@ -129,6 +139,11 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$oldname = 'oldname';
|
$oldname = 'oldname';
|
||||||
$newname = 'newname';
|
$newname = 'newname';
|
||||||
|
|
||||||
|
$this->viewMock->expects($this->at(0))
|
||||||
|
->method('file_exists')
|
||||||
|
->with('/')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->viewMock->expects($this->any())
|
$this->viewMock->expects($this->any())
|
||||||
->method('getFileInfo')
|
->method('getFileInfo')
|
||||||
->will($this->returnValue(array(
|
->will($this->returnValue(array(
|
||||||
|
@ -141,7 +156,6 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
'name' => 'new_name',
|
'name' => 'new_name',
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
|
||||||
$result = $this->files->rename($dir, $oldname, $newname);
|
$result = $this->files->rename($dir, $oldname, $newname);
|
||||||
|
|
||||||
$this->assertTrue($result['success']);
|
$this->assertTrue($result['success']);
|
||||||
|
@ -154,4 +168,35 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']);
|
$this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']);
|
||||||
$this->assertFalse($result['data']['isPreviewAvailable']);
|
$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']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue