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 ;
34- use OCP \Server ;
3536use Psr \Log \LoggerInterface ;
3637
3738/**
@@ -57,10 +58,11 @@ class Scanner extends PublicEmitter {
5758 protected int $ entriesToCommit = 0 ;
5859
5960 public function __construct (
60- private ?string $ user ,
61- protected ?IDBConnection $ db ,
62- private IEventDispatcher $ dispatcher ,
63- protected LoggerInterface $ logger ,
61+ private readonly ?IUser $ user ,
62+ protected readonly ?IDBConnection $ db ,
63+ private readonly IEventDispatcher $ eventDispatcher ,
64+ protected readonly LoggerInterface $ logger ,
65+ private readonly SetupManager $ setupManager ,
6466 ) {
6567 // when DB locking is used, no DB transactions will be used
6668 $ this ->useTransaction = !(Server::get (ILockingProvider::class) instanceof DBLockingProvider);
@@ -74,8 +76,11 @@ public function __construct(
7476 */
7577 protected function getMounts ($ dir ) {
7678 //TODO: move to the node based fileapi once that's done
77- \OC_Util::tearDownFS ();
78- \OC_Util::setupFS ($ this ->user );
79+ $ this ->setupManager ->tearDown ();
80+
81+ if ($ this ->user !== null ) {
82+ $ this ->setupManager ->setupForUser ($ this ->user );
83+ }
7984
8085 $ mountManager = Filesystem::getMountManager ();
8186 $ mounts = $ mountManager ->findIn ($ dir );
@@ -88,37 +93,32 @@ protected function getMounts($dir) {
8893
8994 /**
9095 * attach listeners to the scanner
91- *
92- * @param MountPoint $mount
9396 */
94- protected function attachListener ($ mount ) {
97+ protected function attachListener (MountPoint $ mount ) {
9598 /** @var \OC\Files\Cache\Scanner $scanner */
9699 $ scanner = $ mount ->getStorage ()->getScanner ();
97100 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'scanFile ' , function ($ path ) use ($ mount ): void {
98101 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'scanFile ' , [$ mount ->getMountPoint () . $ path ]);
99- $ this ->dispatcher ->dispatchTyped (new BeforeFileScannedEvent ($ mount ->getMountPoint () . $ path ));
102+ $ this ->eventDispatcher ->dispatchTyped (new BeforeFileScannedEvent ($ mount ->getMountPoint () . $ path ));
100103 });
101104 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'scanFolder ' , function ($ path ) use ($ mount ): void {
102105 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'scanFolder ' , [$ mount ->getMountPoint () . $ path ]);
103- $ this ->dispatcher ->dispatchTyped (new BeforeFolderScannedEvent ($ mount ->getMountPoint () . $ path ));
106+ $ this ->eventDispatcher ->dispatchTyped (new BeforeFolderScannedEvent ($ mount ->getMountPoint () . $ path ));
104107 });
105108 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFile ' , function ($ path ) use ($ mount ): void {
106109 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFile ' , [$ mount ->getMountPoint () . $ path ]);
107- $ this ->dispatcher ->dispatchTyped (new FileScannedEvent ($ mount ->getMountPoint () . $ path ));
110+ $ this ->eventDispatcher ->dispatchTyped (new FileScannedEvent ($ mount ->getMountPoint () . $ path ));
108111 });
109112 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFolder ' , function ($ path ) use ($ mount ): void {
110113 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFolder ' , [$ mount ->getMountPoint () . $ path ]);
111- $ this ->dispatcher ->dispatchTyped (new FolderScannedEvent ($ mount ->getMountPoint () . $ path ));
114+ $ this ->eventDispatcher ->dispatchTyped (new FolderScannedEvent ($ mount ->getMountPoint () . $ path ));
112115 });
113116 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'normalizedNameMismatch ' , function ($ path ) use ($ mount ): void {
114117 $ this ->emit ('\OC\Files\Utils\Scanner ' , 'normalizedNameMismatch ' , [$ path ]);
115118 });
116119 }
117120
118- /**
119- * @param string $dir
120- */
121- public function backgroundScan ($ dir ) {
121+ public function backgroundScan (string $ dir ) {
122122 $ mounts = $ this ->getMounts ($ dir );
123123 foreach ($ mounts as $ mount ) {
124124 try {
@@ -157,13 +157,10 @@ public function backgroundScan($dir) {
157157 }
158158
159159 /**
160- * @param string $dir
161- * @param $recursive
162- * @param callable|null $mountFilter
163160 * @throws ForbiddenException
164161 * @throws NotFoundException
165162 */
166- public function scan ($ dir = '' , $ recursive = \OC \Files \Cache \Scanner::SCAN_RECURSIVE , ?callable $ mountFilter = null ) {
163+ public function scan (string $ dir = '' , $ recursive = \OC \Files \Cache \Scanner::SCAN_RECURSIVE , ?callable $ mountFilter = null ) {
167164 if (!Filesystem::isValidPath ($ dir )) {
168165 throw new \InvalidArgumentException ('Invalid path to scan ' );
169166 }
@@ -219,18 +216,18 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR
219216
220217 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'removeFromCache ' , function ($ path ) use ($ storage ): void {
221218 $ this ->postProcessEntry ($ storage , $ path );
222- $ this ->dispatcher ->dispatchTyped (new NodeRemovedFromCache ($ storage , $ path ));
219+ $ this ->eventDispatcher ->dispatchTyped (new NodeRemovedFromCache ($ storage , $ path ));
223220 });
224221 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'updateCache ' , function ($ path ) use ($ storage ): void {
225222 $ this ->postProcessEntry ($ storage , $ path );
226- $ this ->dispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
223+ $ this ->eventDispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
227224 });
228225 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'addToCache ' , function ($ path , $ storageId , $ data , $ fileId ) use ($ storage ): void {
229226 $ this ->postProcessEntry ($ storage , $ path );
230227 if ($ fileId ) {
231- $ this ->dispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
228+ $ this ->eventDispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
232229 } else {
233- $ this ->dispatcher ->dispatchTyped (new NodeAddedToCache ($ storage , $ path ));
230+ $ this ->eventDispatcher ->dispatchTyped (new NodeAddedToCache ($ storage , $ path ));
234231 }
235232 });
236233
0 commit comments