1010use OC \Files \Cache \Cache ;
1111use OC \Files \Filesystem ;
1212use OC \Files \Mount \MountPoint ;
13+ use OC \Files \SetupManager ;
1314use OC \Files \Storage \FailedStorage ;
1415use OC \Files \Storage \Home ;
1516use OC \ForbiddenException ;
2930use OCP \Files \Storage \IStorage ;
3031use OCP \Files \StorageNotAvailableException ;
3132use OCP \IDBConnection ;
33+ use OCP \IUser ;
3234use OCP \Lock \ILockingProvider ;
3335use OCP \Lock \LockedException ;
3436use OCP \Server ;
@@ -57,10 +59,11 @@ class Scanner extends PublicEmitter {
5759 protected int $ entriesToCommit = 0 ;
5860
5961 public function __construct (
60- private ?string $ user ,
61- protected ?IDBConnection $ db ,
62- private IEventDispatcher $ dispatcher ,
63- protected LoggerInterface $ logger ,
62+ private readonly ?IUser $ user ,
63+ protected readonly ?IDBConnection $ db ,
64+ private readonly IEventDispatcher $ eventDispatcher ,
65+ protected readonly LoggerInterface $ logger ,
66+ private readonly SetupManager $ setupManager ,
6467 ) {
6568 // when DB locking is used, no DB transactions will be used
6669 $ this ->useTransaction = !(Server::get (ILockingProvider::class) instanceof DBLockingProvider);
@@ -74,8 +77,11 @@ public function __construct(
7477 */
7578 protected function getMounts ($ dir ) {
7679 //TODO: move to the node based fileapi once that's done
77- \OC_Util::tearDownFS ();
78- \OC_Util::setupFS ($ this ->user );
80+ $ this ->setupManager ->tearDown ();
81+
82+ if ($ this ->user !== null ) {
83+ $ this ->setupManager ->setupForUser ($ this ->user );
84+ }
7985
8086 $ mountManager = Filesystem::getMountManager ();
8187 $ mounts = $ mountManager ->findIn ($ dir );
@@ -88,37 +94,32 @@ protected function getMounts($dir) {
8894
8995 /**
9096 * attach listeners to the scanner
91- *
92- * @param MountPoint $mount
9397 */
94- protected function attachListener ($ mount ) {
98+ protected function attachListener (MountPoint $ mount ) {
9599 /** @var \OC\Files\Cache\Scanner $scanner */
96100 $ scanner = $ mount ->getStorage ()->getScanner ();
97101 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'scanFile ' , function ($ path ) use ($ mount ): void {
98102 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'scanFile ' , [$ mount ->getMountPoint () . $ path ]);
99- $ this ->dispatcher ->dispatchTyped (new BeforeFileScannedEvent ($ mount ->getMountPoint () . $ path ));
103+ $ this ->eventDispatcher ->dispatchTyped (new BeforeFileScannedEvent ($ mount ->getMountPoint () . $ path ));
100104 });
101105 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'scanFolder ' , function ($ path ) use ($ mount ): void {
102106 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'scanFolder ' , [$ mount ->getMountPoint () . $ path ]);
103- $ this ->dispatcher ->dispatchTyped (new BeforeFolderScannedEvent ($ mount ->getMountPoint () . $ path ));
107+ $ this ->eventDispatcher ->dispatchTyped (new BeforeFolderScannedEvent ($ mount ->getMountPoint () . $ path ));
104108 });
105109 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFile ' , function ($ path ) use ($ mount ): void {
106110 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFile ' , [$ mount ->getMountPoint () . $ path ]);
107- $ this ->dispatcher ->dispatchTyped (new FileScannedEvent ($ mount ->getMountPoint () . $ path ));
111+ $ this ->eventDispatcher ->dispatchTyped (new FileScannedEvent ($ mount ->getMountPoint () . $ path ));
108112 });
109113 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFolder ' , function ($ path ) use ($ mount ): void {
110114 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFolder ' , [$ mount ->getMountPoint () . $ path ]);
111- $ this ->dispatcher ->dispatchTyped (new FolderScannedEvent ($ mount ->getMountPoint () . $ path ));
115+ $ this ->eventDispatcher ->dispatchTyped (new FolderScannedEvent ($ mount ->getMountPoint () . $ path ));
112116 });
113117 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'normalizedNameMismatch ' , function ($ path ) use ($ mount ): void {
114118 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'normalizedNameMismatch ' , [$ path ]);
115119 });
116120 }
117121
118- /**
119- * @param string $dir
120- */
121- public function backgroundScan ($ dir ) {
122+ public function backgroundScan (string $ dir ) {
122123 $ mounts = $ this ->getMounts ($ dir );
123124 foreach ($ mounts as $ mount ) {
124125 try {
@@ -157,13 +158,10 @@ public function backgroundScan($dir) {
157158 }
158159
159160 /**
160- * @param string $dir
161- * @param $recursive
162- * @param callable|null $mountFilter
163161 * @throws ForbiddenException
164162 * @throws NotFoundException
165163 */
166- public function scan ($ dir = '' , $ recursive = \OC \Files \Cache \Scanner::SCAN_RECURSIVE , ?callable $ mountFilter = null ) {
164+ public function scan (string $ dir = '' , $ recursive = \OC \Files \Cache \Scanner::SCAN_RECURSIVE , ?callable $ mountFilter = null ) {
167165 if (!Filesystem::isValidPath ($ dir )) {
168166 throw new \InvalidArgumentException ('Invalid path to scan ' );
169167 }
@@ -219,18 +217,18 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR
219217
220218 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'removeFromCache ' , function ($ path ) use ($ storage ): void {
221219 $ this ->postProcessEntry ($ storage , $ path );
222- $ this ->dispatcher ->dispatchTyped (new NodeRemovedFromCache ($ storage , $ path ));
220+ $ this ->eventDispatcher ->dispatchTyped (new NodeRemovedFromCache ($ storage , $ path ));
223221 });
224222 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'updateCache ' , function ($ path ) use ($ storage ): void {
225223 $ this ->postProcessEntry ($ storage , $ path );
226- $ this ->dispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
224+ $ this ->eventDispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
227225 });
228226 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'addToCache ' , function ($ path , $ storageId , $ data , $ fileId ) use ($ storage ): void {
229227 $ this ->postProcessEntry ($ storage , $ path );
230228 if ($ fileId ) {
231- $ this ->dispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
229+ $ this ->eventDispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
232230 } else {
233- $ this ->dispatcher ->dispatchTyped (new NodeAddedToCache ($ storage , $ path ));
231+ $ this ->eventDispatcher ->dispatchTyped (new NodeAddedToCache ($ storage , $ path ));
234232 }
235233 });
236234
0 commit comments