mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
Merge pull request #33455 from nextcloud/backport/32852/stable24
[stable24] Revert "Revert "Remove inefficient fed share scanner""
This commit is contained in:
commit
d70c7ecc7b
2 changed files with 3 additions and 80 deletions
71
apps/files_sharing/lib/External/Scanner.php
vendored
71
apps/files_sharing/lib/External/Scanner.php
vendored
|
|
@ -29,27 +29,14 @@ use OC\ForbiddenException;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\Files\StorageInvalidException;
|
use OCP\Files\StorageInvalidException;
|
||||||
use OCP\Files\StorageNotAvailableException;
|
use OCP\Files\StorageNotAvailableException;
|
||||||
use OCP\Http\Client\LocalServerException;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
class Scanner extends \OC\Files\Cache\Scanner {
|
class Scanner extends \OC\Files\Cache\Scanner {
|
||||||
/** @var \OCA\Files_Sharing\External\Storage */
|
/** @var \OCA\Files_Sharing\External\Storage */
|
||||||
protected $storage;
|
protected $storage;
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
|
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
|
||||||
try {
|
// Disable locking for federated shares
|
||||||
if (!$this->storage->remoteIsOwnCloud()) {
|
parent::scan($path, $recursive, $reuse, false);
|
||||||
return parent::scan($path, $recursive, $reuse, $lock);
|
|
||||||
}
|
|
||||||
} catch (LocalServerException $e) {
|
|
||||||
// Scanner doesn't have dependency injection
|
|
||||||
\OC::$server->get(LoggerInterface::class)
|
|
||||||
->warning('Trying to scan files inside invalid external storage: ' . $this->storage->getRemote() . ' for mountpoint ' . $this->storage->getMountPoint() . ' and id ' . $this->storage->getId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->scanAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,7 +54,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
|
||||||
*/
|
*/
|
||||||
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
|
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
|
||||||
try {
|
try {
|
||||||
return parent::scanFile($file, $reuseExisting);
|
return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock, $data);
|
||||||
} catch (ForbiddenException $e) {
|
} catch (ForbiddenException $e) {
|
||||||
$this->storage->checkStorageAvailability();
|
$this->storage->checkStorageAvailability();
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
|
|
@ -81,56 +68,4 @@ class Scanner extends \OC\Files\Cache\Scanner {
|
||||||
$this->storage->checkStorageAvailability();
|
$this->storage->checkStorageAvailability();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the remote share for changes.
|
|
||||||
* If changes are available, scan them and update
|
|
||||||
* the cache.
|
|
||||||
* @throws NotFoundException
|
|
||||||
* @throws StorageInvalidException
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function scanAll() {
|
|
||||||
try {
|
|
||||||
$data = $this->storage->getShareInfo();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->storage->checkStorageAvailability();
|
|
||||||
throw new \Exception(
|
|
||||||
'Error while scanning remote share: "' .
|
|
||||||
$this->storage->getRemote() . '" ' .
|
|
||||||
$e->getMessage()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ($data['status'] === 'success') {
|
|
||||||
$this->addResult($data['data'], '');
|
|
||||||
} else {
|
|
||||||
throw new \Exception(
|
|
||||||
'Error while scanning remote share: "' .
|
|
||||||
$this->storage->getRemote() . '"'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @param string $path
|
|
||||||
*/
|
|
||||||
private function addResult($data, $path) {
|
|
||||||
$id = $this->cache->put($path, $data);
|
|
||||||
if (isset($data['children'])) {
|
|
||||||
$children = [];
|
|
||||||
foreach ($data['children'] as $child) {
|
|
||||||
$children[$child['name']] = true;
|
|
||||||
$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$existingCache = $this->cache->getFolderContentsById($id);
|
|
||||||
foreach ($existingCache as $existingChild) {
|
|
||||||
// if an existing child is not in the new data, remove it
|
|
||||||
if (!isset($children[$existingChild['name']])) {
|
|
||||||
$this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,18 +50,6 @@ class ScannerTest extends TestCase {
|
||||||
$this->scanner = new Scanner($this->storage);
|
$this->scanner = new Scanner($this->storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testScanAll() {
|
|
||||||
$this->storage->expects($this->any())
|
|
||||||
->method('getShareInfo')
|
|
||||||
->willReturn(['status' => 'success', 'data' => []]);
|
|
||||||
|
|
||||||
// FIXME add real tests, we are currently only checking for
|
|
||||||
// Declaration of OCA\Files_Sharing\External\Scanner::*() should be
|
|
||||||
// compatible with OC\Files\Cache\Scanner::*()
|
|
||||||
$this->scanner->scanAll();
|
|
||||||
$this->addToAssertionCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testScan() {
|
public function testScan() {
|
||||||
$this->storage->expects($this->any())
|
$this->storage->expects($this->any())
|
||||||
->method('getShareInfo')
|
->method('getShareInfo')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue