Make rename behavior consistent with files app

pull/1/head
Victor Dubiniuk 10 years ago
parent 65f41020c5
commit 29d395f6fd

@ -70,14 +70,19 @@ class DocumentController extends Controller{
public static function rename($args){ public static function rename($args){
$uid = self::preDispatch();
$fileId = intval(@$args['file_id']); $fileId = intval(@$args['file_id']);
$name = @$_POST['name']; $name = @$_POST['name'];
$file = new File($fileId);
$view = \OC\Files\Filesystem::getView();
$path = $view->getPath($fileId);
$l = new \OC_L10n('documents'); $l = new \OC_L10n('documents');
if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) { if (isset($name) && $view->is_file($path) && $view->isUpdatable($path)) {
if ($file->renameTo($name)) { $newPath = dirname($path) . '/' . $name;
// TODO: propagate to other clients if ($view->rename($path, $newPath)) {
\OCP\JSON::success(); \OCP\JSON::success();
return; return;
} }

@ -151,16 +151,6 @@ class File {
return $permissions; return $permissions;
} }
/**
* Rename this file to the given name
* @param string $newName name to give (without path)
* @return boolean true if rename succeeded, false otherwise
*/
public function renameTo($newName) {
list($owner, $path) = $this->getOwnerViewAndPath();
$newPath = dirname($path) . '/' . $newName;
return \OC\Files\Filesystem::rename($path, $newPath);
}
/** /**
* *

Loading…
Cancel
Save