From 584d882c65b2edefc6314c40394f4c00195a432e Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 20 Sep 2013 12:41:37 +0300 Subject: [PATCH] Resolve path to shared items for current user --- ajax/sessionController.php | 4 ++-- lib/storage.php | 28 +++++++++++++++++++--------- lib/view.php | 13 ++++++------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ajax/sessionController.php b/ajax/sessionController.php index e20ce937..04f90b3a 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -75,11 +75,11 @@ class SessionController extends Controller{ } $path = Storage::getFilePath($session['file_id']); - $view = new \OC\Files\View('/' . $session['owner']); + $view = new \OC\Files\View('/' . $uid); $isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path); if (!$isWritable){ - throw new \Exception('Document does not exist or is not writable for this user'); + throw new \Exception($path . ' does not exist or is not writable for user ' . $uid); } if ($view->file_exists($path)){ diff --git a/lib/storage.php b/lib/storage.php index 27d7fcf0..cd1dbf4f 100755 --- a/lib/storage.php +++ b/lib/storage.php @@ -55,20 +55,30 @@ class Storage { $path = @$fileInfo[1]; if (!$path){ - throw new \Exception('File not found in cache'); + throw new \Exception($fileId . ' can not be resolved'); } - // Strip /files infront of the path - $normalizedPath = preg_replace('/^\/?files/', '', $path); - if (!\OC\Files\Filesystem::file_exists($path) - && \OC\Files\Filesystem::file_exists('/Shared' . $normalizedPath) - && \OC\Files\Filesystem::is_file('/Shared' . $normalizedPath) - ){ + $internalPath = preg_replace('/^\/?files/', '', $path); + if (!\OC\Files\Filesystem::file_exists($internalPath)){ + $sharedInfo = \OCP\Share::getItemSharedWithBySource( + 'file', + $fileId, + \OCP\Share::FORMAT_NONE, + null, + true + ); + if (!$sharedInfo){ + throw new \Exception($path . ' can not be resolved in shared cache'); + } // this file is shared - $normalizedPath = '/Shared' . $normalizedPath; + $internalPath = 'Shared' . $sharedInfo['file_target']; } - return $normalizedPath; + if (!\OC\Files\Filesystem::file_exists($internalPath)){ + throw new \Exception($path . ' doesn\'t exist'); + } + + return 'files/' . $internalPath; } /** diff --git a/lib/view.php b/lib/view.php index 78074a36..90e61fed 100644 --- a/lib/view.php +++ b/lib/view.php @@ -36,18 +36,17 @@ class View extends \OC\Files\View{ $view = new \OC\Files\View('/' . $uid); - $relPath = '/files' . $filePath; - if (!$view->file_exists($relPath)){ - throw new \Exception('Original document doesn\'t exist any more'); + if (!$view->file_exists($filePath)){ + throw new \Exception($filePath . ' doesn\'t exist'); } - if (!$view->is_file($relPath)){ - throw new \Exception('Object ' . $relPath . ' is not a file.'); + if (!$view->is_file($filePath)){ + throw new \Exception('Object ' . $filePath . ' is not a file.'); } - $newName = '/' . sha1($view->file_get_contents($relPath)) . '.odt'; + $newName = '/' . sha1($view->file_get_contents($filePath)) . '.odt'; - $view->copy($relPath, self::DOCUMENTS_DIRNAME . $newName); + $view->copy($filePath, self::DOCUMENTS_DIRNAME . $newName); \OC_FileProxy::$enabled = $proxyStatus; return $newName; }