de-deplicate getUidAndFilename
This commit is contained in:
parent
fd2e1086c6
commit
300eb54c87
4 changed files with 29 additions and 33 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue