2929use OCP \Files \NotFoundException ;
3030use OCP \Files \StorageInvalidException ;
3131use OCP \Files \StorageNotAvailableException ;
32- use OCP \Http \Client \LocalServerException ;
33- use Psr \Log \LoggerInterface ;
3432
3533class 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}
0 commit comments