99namespace OCA \Files_External \Service ;
1010
1111use OC \Files \Cache \CacheEntry ;
12+ use OC \Files \Storage \FailedStorage ;
1213use OC \User \LazyUser ;
1314use OCA \Files_External \Config \ConfigAdapter ;
1415use OCA \Files_External \Event \StorageCreatedEvent ;
1718use OCA \Files_External \Lib \StorageConfig ;
1819use OCP \Cache \CappedMemoryCache ;
1920use OCP \EventDispatcher \Event ;
20- use OCP \EventDispatcher \Event as T ;
2121use OCP \EventDispatcher \IEventListener ;
2222use OCP \Files \Cache \ICacheEntry ;
2323use OCP \Files \Config \IUserMountCache ;
@@ -132,16 +132,20 @@ public function registerUpdatedStorage(StorageConfig $oldStorage, StorageConfig
132132 }
133133
134134 private function getCacheEntryForRoot (IUser $ user , StorageConfig $ storage ): ICacheEntry {
135- $ storage = $ this ->configAdapter ->constructStorageForUser ($ user , $ storage );
135+ try {
136+ $ userStorage = $ this ->configAdapter ->constructStorageForUser ($ user , clone $ storage );
137+ } catch (\Exception $ e ) {
138+ $ userStorage = new FailedStorage (['exception ' => $ e ]);
139+ }
136140
137- if ($ cachedEntry = $ this ->storageRootCache ->get ($ storage ->getId ())) {
141+ if ($ cachedEntry = $ this ->storageRootCache ->get ($ userStorage ->getId ())) {
138142 return $ cachedEntry ;
139143 }
140144
141- $ cache = $ storage ->getCache ();
145+ $ cache = $ userStorage ->getCache ();
142146 $ entry = $ cache ->get ('' );
143- if ($ entry ) {
144- $ this ->storageRootCache ->set ($ storage ->getId (), $ entry );
147+ if ($ entry && $ entry -> getId () !== - 1 ) {
148+ $ this ->storageRootCache ->set ($ userStorage ->getId (), $ entry );
145149 return $ entry ;
146150 }
147151
@@ -163,10 +167,14 @@ private function getCacheEntryForRoot(IUser $user, StorageConfig $storage): ICac
163167 'encrypted ' => 0 ,
164168 'checksum ' => '' ,
165169 ];
166- $ data ['fileid ' ] = $ cache ->insert ('' , $ data );
170+ if ($ cache ->getNumericStorageId () !== -1 ) {
171+ $ data ['fileid ' ] = $ cache ->insert ('' , $ data );
172+ } else {
173+ $ data ['fileid ' ] = -1 ;
174+ }
167175
168176 $ entry = new CacheEntry ($ data );
169- $ this ->storageRootCache ->set ($ storage ->getId (), $ entry );
177+ $ this ->storageRootCache ->set ($ userStorage ->getId (), $ entry );
170178 return $ entry ;
171179 }
172180
0 commit comments