Skip to content

Commit d70c7ec

Browse files
authored
Merge pull request #33455 from nextcloud/backport/32852/stable24
[stable24] Revert "Revert "Remove inefficient fed share scanner""
2 parents d26c098 + 1d66a53 commit d70c7ec

File tree

2 files changed

+3
-80
lines changed

2 files changed

+3
-80
lines changed

apps/files_sharing/lib/External/Scanner.php

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,14 @@
2929
use OCP\Files\NotFoundException;
3030
use OCP\Files\StorageInvalidException;
3131
use OCP\Files\StorageNotAvailableException;
32-
use OCP\Http\Client\LocalServerException;
33-
use Psr\Log\LoggerInterface;
3432

3533
class Scanner extends \OC\Files\Cache\Scanner {
3634
/** @var \OCA\Files_Sharing\External\Storage */
3735
protected $storage;
3836

39-
/** {@inheritDoc} */
4037
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
41-
try {
42-
if (!$this->storage->remoteIsOwnCloud()) {
43-
return parent::scan($path, $recursive, $reuse, $lock);
44-
}
45-
} catch (LocalServerException $e) {
46-
// Scanner doesn't have dependency injection
47-
\OC::$server->get(LoggerInterface::class)
48-
->warning('Trying to scan files inside invalid external storage: ' . $this->storage->getRemote() . ' for mountpoint ' . $this->storage->getMountPoint() . ' and id ' . $this->storage->getId());
49-
return;
50-
}
51-
52-
$this->scanAll();
38+
// Disable locking for federated shares
39+
parent::scan($path, $recursive, $reuse, false);
5340
}
5441

5542
/**
@@ -67,7 +54,7 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
6754
*/
6855
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
6956
try {
70-
return parent::scanFile($file, $reuseExisting);
57+
return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock, $data);
7158
} catch (ForbiddenException $e) {
7259
$this->storage->checkStorageAvailability();
7360
} catch (NotFoundException $e) {
@@ -81,56 +68,4 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
8168
$this->storage->checkStorageAvailability();
8269
}
8370
}
84-
85-
/**
86-
* Checks the remote share for changes.
87-
* If changes are available, scan them and update
88-
* the cache.
89-
* @throws NotFoundException
90-
* @throws StorageInvalidException
91-
* @throws \Exception
92-
*/
93-
public function scanAll() {
94-
try {
95-
$data = $this->storage->getShareInfo();
96-
} catch (\Exception $e) {
97-
$this->storage->checkStorageAvailability();
98-
throw new \Exception(
99-
'Error while scanning remote share: "' .
100-
$this->storage->getRemote() . '" ' .
101-
$e->getMessage()
102-
);
103-
}
104-
if ($data['status'] === 'success') {
105-
$this->addResult($data['data'], '');
106-
} else {
107-
throw new \Exception(
108-
'Error while scanning remote share: "' .
109-
$this->storage->getRemote() . '"'
110-
);
111-
}
112-
}
113-
114-
/**
115-
* @param array $data
116-
* @param string $path
117-
*/
118-
private function addResult($data, $path) {
119-
$id = $this->cache->put($path, $data);
120-
if (isset($data['children'])) {
121-
$children = [];
122-
foreach ($data['children'] as $child) {
123-
$children[$child['name']] = true;
124-
$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
125-
}
126-
127-
$existingCache = $this->cache->getFolderContentsById($id);
128-
foreach ($existingCache as $existingChild) {
129-
// if an existing child is not in the new data, remove it
130-
if (!isset($children[$existingChild['name']])) {
131-
$this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
132-
}
133-
}
134-
}
135-
}
13671
}

apps/files_sharing/tests/External/ScannerTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ protected function setUp(): void {
5050
$this->scanner = new Scanner($this->storage);
5151
}
5252

53-
public function testScanAll() {
54-
$this->storage->expects($this->any())
55-
->method('getShareInfo')
56-
->willReturn(['status' => 'success', 'data' => []]);
57-
58-
// FIXME add real tests, we are currently only checking for
59-
// Declaration of OCA\Files_Sharing\External\Scanner::*() should be
60-
// compatible with OC\Files\Cache\Scanner::*()
61-
$this->scanner->scanAll();
62-
$this->addToAssertionCount(1);
63-
}
64-
6553
public function testScan() {
6654
$this->storage->expects($this->any())
6755
->method('getShareInfo')

0 commit comments

Comments
 (0)