Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont delegate Mount\Manager::getByNumericId to getByStorageId #36566

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,13 @@ public function getAll(): array {
* @return IMountPoint[]
*/
public function findByNumericId(int $id): array {
$storageId = \OC\Files\Cache\Storage::getStorageId($id);
return $this->findByStorageId($storageId);
$result = [];
foreach ($this->mounts as $mount) {
if ($mount->getNumericStorageId() === $id) {
$result[] = $mount;
}
}
return $result;
}

/**
Expand Down
24 changes: 14 additions & 10 deletions lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MountPoint implements IMountPoint {
protected $storage = null;
protected $class;
protected $storageId;
protected $numericStorageId = null;
protected $rootId = null;

/**
Expand Down Expand Up @@ -195,19 +196,15 @@ public function getStorage() {
}

/**
* @return string
* @return string|null
Fixed Show fixed Hide fixed
*/
public function getStorageId() {
if (!$this->storageId) {
if (is_null($this->storage)) {
$storage = $this->createStorage(); //FIXME: start using exceptions
if (is_null($storage)) {
return null;
}

$this->storage = $storage;
$storage = $this->getStorage();
if (is_null($storage)) {
return null;
}
$this->storageId = $this->storage->getId();
$this->storageId = $storage->getId();
if (strlen($this->storageId) > 64) {
$this->storageId = md5($this->storageId);
}
Expand All @@ -219,7 +216,14 @@ public function getStorageId() {
* @return int
*/
public function getNumericStorageId() {
return $this->getStorage()->getStorageCache()->getNumericId();
if (is_null($this->numericStorageId)) {
$storage = $this->getStorage();
if (is_null($storage)) {
return -1;
}
$this->numericStorageId = $storage->getStorageCache()->getNumericId();
}
return $this->numericStorageId;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Files/Mount/IMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public function getStorage();
/**
* Get the id of the storages
*
* @return string
* @return string|null
* @since 8.0.0
*/
public function getStorageId();

/**
* Get the id of the storages
*
* @return int
* @return int|null
* @since 9.1.0
*/
public function getNumericStorageId();
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,9 @@ private function createTestMovableMountPoints($mountPoints) {
->setConstructorArgs([[]])
->getMock();
$storage->method('getId')->willReturn('non-null-id');
$storage->method('getStorageCache')->willReturnCallback(function () use ($storage) {
return new \OC\Files\Cache\Storage($storage);
});

$mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
->setMethods(['moveMount'])
Expand Down