From bd4d65d0022a511bf81b24c3edb11240d6d0b09b Mon Sep 17 00:00:00 2001 From: nadir Date: Wed, 2 Mar 2016 18:01:23 +0100 Subject: [PATCH] Fixes over OCS Optimization - Missing constant TOKEN_LENGTH fix - Fix when sharing a folder (we dont create a version of folders) - Fix when retrieving share information from a folder (it was trying to access the "version" of the folder) --- apps/files_sharing/api/customlocal.php | 24 +++++++++++++++----- apps/files_sharing/api/linkshareexecutor.php | 2 +- apps/files_sharing/api/shareexecutor.php | 13 +++++++++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/apps/files_sharing/api/customlocal.php b/apps/files_sharing/api/customlocal.php index 3e5fdb2a3948..e18fe85f85e4 100644 --- a/apps/files_sharing/api/customlocal.php +++ b/apps/files_sharing/api/customlocal.php @@ -165,7 +165,7 @@ public static function createShare($params) $data['token'] = $token; } - return new \OC_OCS_Result([$data]); + return new \OC_OCS_Result($data); } else { @@ -264,9 +264,13 @@ private static function getSharedFilesInFolder($path) $basename = basename($versionMeta['eospath']); if($row['item_type'] === 'file') + { $realfile = $dirname . "/" . substr($basename, 8); - else - $realfile = $dirname . "/" . $basename; + } + else + { + $realfile = $dirname . "/" . $basename; + } //$realfile = $dirname . "/" . substr($basename, 8); @@ -303,6 +307,7 @@ private static function getSharedFileInfo($path) { $username = \OCP\User::getUser(); $view = new \OC\Files\View('/'.$username.'/files'); + $fileInfo = $view->getFileInfo($path); $eosPath = EosProxy::toEos('files' . $path, 'object::user:'.$username); $originalEosMeta = EosUtil::getFileByEosPath($eosPath); @@ -311,9 +316,16 @@ private static function getSharedFileInfo($path) { $dirname = dirname($eosPath); $basename = basename($eosPath); - $versionFolder = $dirname . "/.sys.v#." . $basename; - - $eosMeta = EosUtil::getFileByEosPath($versionFolder, false); + $eosMeta = null; + if($fileInfo['eostype'] === 'file') + { + $versionFolder = $dirname . "/.sys.v#." . $basename; + $eosMeta = EosUtil::getFileByEosPath($versionFolder, false); + } + else + { + $eosMeta = $fileInfo; + } if($eosMeta === null) { diff --git a/apps/files_sharing/api/linkshareexecutor.php b/apps/files_sharing/api/linkshareexecutor.php index b4f0efc27d97..e7135ca85b87 100644 --- a/apps/files_sharing/api/linkshareexecutor.php +++ b/apps/files_sharing/api/linkshareexecutor.php @@ -132,7 +132,7 @@ public function checkForPreviousShares() if (isset($oldToken)) { $this->token = $oldToken; } else { - $this->token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(self::TOKEN_LENGTH, + $this->token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(\OC\Share\Share::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_UPPER. \OCP\Security\ISecureRandom::CHAR_DIGITS); } diff --git a/apps/files_sharing/api/shareexecutor.php b/apps/files_sharing/api/shareexecutor.php index bb2d1198d0c5..0e233ce45279 100644 --- a/apps/files_sharing/api/shareexecutor.php +++ b/apps/files_sharing/api/shareexecutor.php @@ -31,11 +31,20 @@ public function __construct($path) { $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); $this->meta = $view->getFileInfo($path); - $this->versionMeta = \OC\Files\ObjectStore\EosUtil::getVersionFolderFromFileId($this->meta['fileid']); - $this->itemSource = $this->versionMeta['fileid']; $this->itemType = $this->meta['mimetype'] === 'httpd/unix-directory' ? 'folder' : 'file'; + if($this->itemType === 'file') + { + $this->versionMeta = \OC\Files\ObjectStore\EosUtil::getVersionFolderFromFileId($this->meta['fileid']); + } + else + { + $this->versionMeta = $this->meta; + } + + $this->itemSource = $this->versionMeta['fileid']; + if($this->itemSource === null) { throw new \Exception("wrong path, file/folder doesn't exist.");