From fd2e1086c69e2c4c237e8ceab06f8948983bbb17 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 10 Dec 2015 14:05:27 +0100 Subject: [PATCH 1/6] dont return an owner for files that don't exist --- lib/private/files/view.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 357f854e5e..6bc1ac46ef 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1573,10 +1573,15 @@ class View { * Get the owner for a file or folder * * @param string $path - * @return string + * @return string the user id of the owner + * @throws NotFoundException */ public function getOwner($path) { - return $this->basicOperation('getOwner', $path); + $info = $this->getFileInfo($path); + if (!$info) { + throw new NotFoundException($path . 'not found while trying to get owner'); + } + return $info->getOwner()->getUID(); } /** From 300eb54c871cfe48165ee32ecdc5067226aa0b7b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 10 Dec 2015 14:14:54 +0100 Subject: [PATCH 2/6] de-deplicate getUidAndFilename --- apps/files_sharing/lib/helper.php | 10 ++-------- apps/files_trashbin/lib/trashbin.php | 13 +------------ apps/files_versions/lib/storage.php | 14 ++------------ lib/private/files/view.php | 25 ++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index 391b491e1f..cfc9033f3b 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -28,6 +28,7 @@ */ namespace OCA\Files_Sharing; +use OC\Files\Filesystem; use OCP\Files\NotFoundException; class Helper { @@ -205,14 +206,7 @@ class Helper { } public static function getUidAndFilename($filename) { - $uid = \OC\Files\Filesystem::getOwner($filename); - \OC\Files\Filesystem::initMountPoints($uid); - if ( $uid != \OCP\User::getUser() ) { - $info = \OC\Files\Filesystem::getFileInfo($filename); - $ownerView = new \OC\Files\View('/'.$uid.'/files'); - $filename = $ownerView->getPath($info['fileid']); - } - return array($uid, $filename); + return Filesystem::getView()->getUidAndFilename($filename); } /** diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index bd6798f0ef..874aceaad1 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -71,18 +71,7 @@ class Trashbin { * @throws \OC\User\NoUserException */ public static function getUidAndFilename($filename) { - $uid = \OC\Files\Filesystem::getOwner($filename); - \OC\Files\Filesystem::initMountPoints($uid); - if ($uid != \OCP\User::getUser()) { - $info = \OC\Files\Filesystem::getFileInfo($filename); - $ownerView = new \OC\Files\View('/' . $uid . '/files'); - try { - $filename = $ownerView->getPath($info['fileid']); - } catch (NotFoundException $e) { - $filename = null; - } - } - return [$uid, $filename]; + return Filesystem::getView()->getUidAndFilename($filename); } /** diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index 21b5e9e0e7..e131284165 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -41,6 +41,7 @@ namespace OCA\Files_Versions; +use OC\Files\Filesystem; use OCA\Files_Versions\AppInfo\Application; use OCA\Files_Versions\Command\Expire; use OCP\Lock\ILockingProvider; @@ -81,18 +82,7 @@ class Storage { * @throws \OC\User\NoUserException */ public static function getUidAndFilename($filename) { - $uid = \OC\Files\Filesystem::getOwner($filename); - \OC\Files\Filesystem::initMountPoints($uid); - if ( $uid != \OCP\User::getUser() ) { - $info = \OC\Files\Filesystem::getFileInfo($filename); - $ownerView = new \OC\Files\View('/'.$uid.'/files'); - try { - $filename = $ownerView->getPath($info['fileid']); - } catch (NotFoundException $e) { - $filename = null; - } - } - return [$uid, $filename]; + return Filesystem::getView()->getUidAndFilename($filename); } /** diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 6bc1ac46ef..1919795098 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -44,7 +44,6 @@ namespace OC\Files; use Icewind\Streams\CallbackWrapper; -use OC\Files\Cache\Updater; use OC\Files\Mount\MoveableMount; use OC\Files\Storage\Storage; use OC\User\User; @@ -2017,4 +2016,28 @@ class View { } return ''; } + + /** + * @param string $filename + * @return array + * @throws \OC\User\NoUserException + * @throws NotFoundException + */ + public function getUidAndFilename($filename) { + $info = $this->getFileInfo($filename); + if (!$info instanceof \OCP\Files\FileInfo) { + throw new NotFoundException($this->getAbsolutePath($filename) . 'not found'); + } + $uid = $info->getOwner()->getUID(); + if ($uid != \OCP\User::getUser()) { + Filesystem::initMountPoints($uid); + $ownerView = new View('/' . $uid . '/files'); + try { + $filename = $ownerView->getPath($info['fileid']); + } catch (NotFoundException $e) { + throw new NotFoundException('File with id ' . $info['fileid'] . 'not found for user ' . $uid); + } + } + return [$uid, $filename]; + } } From 3e8a5f8a532c3fb68b570ddfcb1916abbe5d7bcb Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 14 Dec 2015 10:24:38 +0100 Subject: [PATCH 3/6] Typo in error message --- lib/private/files/view.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 1919795098..240e2a143b 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1578,7 +1578,7 @@ class View { public function getOwner($path) { $info = $this->getFileInfo($path); if (!$info) { - throw new NotFoundException($path . 'not found while trying to get owner'); + throw new NotFoundException($path . ' not found while trying to get owner'); } return $info->getOwner()->getUID(); } @@ -2026,7 +2026,7 @@ class View { public function getUidAndFilename($filename) { $info = $this->getFileInfo($filename); if (!$info instanceof \OCP\Files\FileInfo) { - throw new NotFoundException($this->getAbsolutePath($filename) . 'not found'); + throw new NotFoundException($this->getAbsolutePath($filename) . ' not found'); } $uid = $info->getOwner()->getUID(); if ($uid != \OCP\User::getUser()) { @@ -2035,7 +2035,7 @@ class View { try { $filename = $ownerView->getPath($info['fileid']); } catch (NotFoundException $e) { - throw new NotFoundException('File with id ' . $info['fileid'] . 'not found for user ' . $uid); + throw new NotFoundException('File with id ' . $info['fileid'] . ' not found for user ' . $uid); } } return [$uid, $filename]; From 8890c88c119f9b1faaa6e60b3230561d8942973e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 14 Dec 2015 13:35:37 +0100 Subject: [PATCH 4/6] handle not found in trash hook --- apps/files_trashbin/lib/trashbin.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 874aceaad1..b2fb51226c 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -62,7 +62,11 @@ class Trashbin { * @param array $params */ public static function ensureFileScannedHook($params) { - self::getUidAndFilename($params['path']); + try { + self::getUidAndFilename($params['path']); + } catch (NotFoundException $e) { + // nothing to scan for non existing files + } } /** From 282f67dad126da438bfe8a0a89ad0aba21651c75 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 14 Dec 2015 14:16:06 +0100 Subject: [PATCH 5/6] improve handling of non existing files in the trashbin --- apps/files_versions/lib/storage.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index e131284165..82b0d896fa 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -42,6 +42,8 @@ namespace OCA\Files_Versions; use OC\Files\Filesystem; +use OC\Search\Provider\File; +use OCA\Activity\Extension\Files; use OCA\Files_Versions\AppInfo\Application; use OCA\Files_Versions\Command\Expire; use OCP\Lock\ILockingProvider; @@ -135,7 +137,12 @@ class Storage { // to get the right target $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext === 'part') { - $filename = substr($filename, 0, strlen($filename)-5); + $filename = substr($filename, 0, strlen($filename) - 5); + } + + // we only handle existing files + if (! Filesystem::file_exists($filename) || Filesystem::is_dir($filename)) { + return false; } list($uid, $filename) = self::getUidAndFilename($filename); @@ -143,15 +150,8 @@ class Storage { $files_view = new \OC\Files\View('/'.$uid .'/files'); $users_view = new \OC\Files\View('/'.$uid); - // check if filename is a directory - if($files_view->is_dir($filename)) { - return false; - } - - // we should have a source file to work with, and the file shouldn't - // be empty - $fileExists = $files_view->file_exists($filename); - if (!($fileExists && $files_view->filesize($filename) > 0)) { + // no use making versions for empty files + if ($files_view->filesize($filename) === 0) { return false; } @@ -638,6 +638,11 @@ class Storage { $expiration = self::getExpiration(); if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) { + + if (!Filesystem::file_exists($filename)) { + return false; + } + list($uid, $filename) = self::getUidAndFilename($filename); if (empty($filename)) { // file maybe renamed or deleted From 94200b682cacbbb5fe673fad64ec5bf1d12f34fc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 15 Dec 2015 13:00:13 +0100 Subject: [PATCH 6/6] removed unused imports --- apps/files_versions/lib/storage.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index 82b0d896fa..5596779f8f 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -42,12 +42,9 @@ namespace OCA\Files_Versions; use OC\Files\Filesystem; -use OC\Search\Provider\File; -use OCA\Activity\Extension\Files; use OCA\Files_Versions\AppInfo\Application; use OCA\Files_Versions\Command\Expire; use OCP\Lock\ILockingProvider; -use OCP\Files\NotFoundException; class Storage {