Merge pull request #21117 from owncloud/owner-file-exists

Only return an owner if the file exists + improved getUidAndFilename
This commit is contained in:
Thomas Müller 2016-01-15 13:31:56 +01:00
commit 6824704699
4 changed files with 54 additions and 46 deletions

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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];
}
}