Skip to content

Commit

Permalink
optimize isShared and isMounted
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Nov 8, 2023
1 parent dec880b commit f4fa2fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
*/
namespace OC\Files;

use OCA\Files_Sharing\ISharedStorage;
use OC\Files\Mount\HomeMountPoint;
use OCA\Files_Sharing\External\Mount;
use OCA\Files_Sharing\ISharedMountPoint;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\IHomeStorage;
use OCP\Files\Mount\IMountPoint;
use OCP\IUser;

Expand Down Expand Up @@ -312,13 +313,12 @@ public function isShareable() {
* @return bool
*/
public function isShared() {
$storage = $this->getStorage();
return $storage->instanceOfStorage(ISharedStorage::class);
return $this->mount instanceof ISharedMountPoint;
}

public function isMounted() {
$storage = $this->getStorage();
return !($storage->instanceOfStorage(IHomeStorage::class) || $storage->instanceOfStorage(ISharedStorage::class));
$isHome = $this->mount instanceof HomeMountPoint;
return !$isHome && !$this->isShared();
}

/**
Expand Down
18 changes: 14 additions & 4 deletions tests/lib/Files/FileInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,19 +35,27 @@ public function testIsMountedHomeStorage() {
->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());
}
}

0 comments on commit f4fa2fb

Please sign in to comment.