Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-06-10 11:29:23 +0300
committerCarl Schwan <carl@carlschwan.eu>2022-06-13 11:08:43 +0300
commit21f52f6670f186d2b1dd02d6916b5053bc35491e (patch)
tree1ba11aafe692069950407c6f618ad5a2b55e1d06 /apps/files_sharing/lib
parent47455533dc1349147e8dc081c28572a4ac9df53a (diff)
Revert "Remove inefficient fed share scanner"
This reverts commit ce319143142e2ee998ef4794b04ad684c4ffa911. Signed-off-by: Carl Schwan <carl@carlschwan.eu> (cherry picked from commit 6667007bf235b90a7dd105c881cf5802b2a3f83e)
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/External/Scanner.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php
index 009e206b959..cfde56103da 100644
--- a/apps/files_sharing/lib/External/Scanner.php
+++ b/apps/files_sharing/lib/External/Scanner.php
@@ -29,11 +29,29 @@ use OC\ForbiddenException;
use OCP\Files\NotFoundException;
use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
+use OCP\Http\Client\LocalServerException;
+use Psr\Log\LoggerInterface;
class Scanner extends \OC\Files\Cache\Scanner {
/** @var \OCA\Files_Sharing\External\Storage */
protected $storage;
+ /** {@inheritDoc} */
+ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
+ try {
+ if (!$this->storage->remoteIsOwnCloud()) {
+ 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();
+ }
+
/**
* Scan a single file and store it in the cache.
* If an exception happened while accessing the external storage,
@@ -63,4 +81,56 @@ class Scanner extends \OC\Files\Cache\Scanner {
$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'], '/'));
+ }
+ }
+ }
+ }
}