summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_sharing/lib/helper.php10
-rw-r--r--apps/files_trashbin/lib/trashbin.php19
-rw-r--r--apps/files_versions/lib/storage.php38
-rw-r--r--lib/private/files/view.php33
4 files changed, 54 insertions, 46 deletions
diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php
index ca60f622844..cffdc8887ec 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 fdca25ff457..ca3a8b178a2 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -63,7 +63,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
+ }
}
/**
@@ -72,18 +76,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 74bf8fea49d..35b3110928b 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -41,10 +41,10 @@
namespace OCA\Files_Versions;
+use OC\Files\Filesystem;
use OCA\Files_Versions\AppInfo\Application;
use OCA\Files_Versions\Command\Expire;
use OCP\Lock\ILockingProvider;
-use OCP\Files\NotFoundException;
class Storage {
@@ -81,18 +81,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);
}
/**
@@ -145,7 +134,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);
@@ -153,15 +147,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;
}
@@ -648,6 +635,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
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 55b8da165e1..d4cc24ae0f5 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();
}
/**
@@ -2021,4 +2026,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];
+ }
}