mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
optimize isShared and isMounted
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
bdba3f1e2f
commit
81d625d44d
2 changed files with 19 additions and 22 deletions
|
|
@ -32,6 +32,8 @@
|
|||
*/
|
||||
namespace OC\Files;
|
||||
|
||||
use OC\Files\Mount\HomeMountPoint;
|
||||
use OCA\Files_Sharing\ISharedMountPoint;
|
||||
use OCP\Files\Cache\ICacheEntry;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\IUser;
|
||||
|
|
@ -309,27 +311,12 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
|
|||
* @return bool
|
||||
*/
|
||||
public function isShared() {
|
||||
$sid = $this->getStorage()->getId();
|
||||
if (!is_null($sid)) {
|
||||
$sid = explode(':', $sid);
|
||||
return ($sid[0] === 'shared');
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->mount instanceof ISharedMountPoint;
|
||||
}
|
||||
|
||||
public function isMounted() {
|
||||
$storage = $this->getStorage();
|
||||
if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
|
||||
return false;
|
||||
}
|
||||
$sid = $storage->getId();
|
||||
if (!is_null($sid)) {
|
||||
$sid = explode(':', $sid);
|
||||
return ($sid[0] !== 'home' and $sid[0] !== 'shared');
|
||||
}
|
||||
|
||||
return false;
|
||||
$isHome = $this->mount instanceof HomeMountPoint;
|
||||
return !$isHome && !$this->isShared();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
namespace Test\Files;
|
||||
|
||||
use OC\Files\FileInfo;
|
||||
use OC\Files\Mount\HomeMountPoint;
|
||||
use OC\Files\Mount\MountPoint;
|
||||
use OC\Files\Storage\Home;
|
||||
use OC\Files\Storage\Temporary;
|
||||
use OCP\IConfig;
|
||||
|
|
@ -33,19 +35,27 @@ class FileInfoTest extends TestCase {
|
|||
->willReturn('foo');
|
||||
$user->method('getHome')
|
||||
->willReturn('foo');
|
||||
$storage = new Home(['user' => $user]);
|
||||
|
||||
$fileInfo = new FileInfo(
|
||||
'',
|
||||
new Home(['user' => $user]),
|
||||
'', [], null);
|
||||
$storage,
|
||||
'',
|
||||
[],
|
||||
new HomeMountPoint($user, $storage, '/foo/files')
|
||||
);
|
||||
$this->assertFalse($fileInfo->isMounted());
|
||||
}
|
||||
|
||||
public function testIsMountedNonHomeStorage() {
|
||||
$storage = new Temporary();
|
||||
$fileInfo = new FileInfo(
|
||||
'',
|
||||
new Temporary(),
|
||||
'', [], null);
|
||||
$storage,
|
||||
'',
|
||||
[],
|
||||
new MountPoint($storage, '/foo/files/bar')
|
||||
);
|
||||
$this->assertTrue($fileInfo->isMounted());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue