From 300eb54c871cfe48165ee32ecdc5067226aa0b7b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 10 Dec 2015 14:14:54 +0100 Subject: [PATCH] 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]; + } }