1010use OC \Files \Filesystem ;
1111use OC \Files \View ;
1212use OCP \ICache ;
13+ use OCP \IUserSession ;
1314use OCP \Security \ISecureRandom ;
15+ use OCP \Server ;
1416use Psr \Log \LoggerInterface ;
1517
1618class File implements ICache {
@@ -28,17 +30,18 @@ protected function getStorage() {
2830 if ($ this ->storage !== null ) {
2931 return $ this ->storage ;
3032 }
31- if (\OC ::$ server ->getUserSession ()->isLoggedIn ()) {
33+ $ session = Server::get (IUserSession::class);
34+ if ($ session ->isLoggedIn ()) {
3235 $ rootView = new View ();
33- $ user = \ OC :: $ server -> getUserSession ()->getUser ();
34- Filesystem::initMountPoints ($ user -> getUID () );
35- if (!$ rootView ->file_exists ('/ ' . $ user -> getUID () . '/cache ' )) {
36- $ rootView ->mkdir ('/ ' . $ user -> getUID () . '/cache ' );
36+ $ userId = $ session -> getUser ()->getUID ();
37+ Filesystem::initMountPoints ($ userId );
38+ if (!$ rootView ->file_exists ('/ ' . $ userId . '/cache ' )) {
39+ $ rootView ->mkdir ('/ ' . $ userId . '/cache ' );
3740 }
38- $ this ->storage = new View ('/ ' . $ user -> getUID () . '/cache ' );
41+ $ this ->storage = new View ('/ ' . $ userId . '/cache ' );
3942 return $ this ->storage ;
4043 } else {
41- \ OCP \ Server::get (LoggerInterface::class)->error ('Can \'t get cache storage, user not logged in ' , ['app ' => 'core ' ]);
44+ Server::get (LoggerInterface::class)->error ('Can \'t get cache storage, user not logged in ' , ['app ' => 'core ' ]);
4245 throw new \OC \ForbiddenException ('Can\t get cache storage, user not logged in ' );
4346 }
4447 }
@@ -83,15 +86,15 @@ public function set($key, $value, $ttl = 0) {
8386 $ storage = $ this ->getStorage ();
8487 $ result = false ;
8588 // unique id to avoid chunk collision, just in case
86- $ uniqueId = \ OC :: $ server -> get (ISecureRandom::class)->generate (
89+ $ uniqueId = Server:: get (ISecureRandom::class)->generate (
8790 16 ,
8891 ISecureRandom::CHAR_ALPHANUMERIC
8992 );
9093
9194 // use part file to prevent hasKey() to find the key
9295 // while it is being written
9396 $ keyPart = $ key . '. ' . $ uniqueId . '.part ' ;
94- if ($ storage and $ storage ->file_put_contents ($ keyPart , $ value )) {
97+ if ($ storage && $ storage ->file_put_contents ($ keyPart , $ value )) {
9598 if ($ ttl === 0 ) {
9699 $ ttl = 86400 ; // 60*60*24
97100 }
@@ -134,11 +137,11 @@ public function remove($key) {
134137 */
135138 public function clear ($ prefix = '' ) {
136139 $ storage = $ this ->getStorage ();
137- if ($ storage and $ storage ->is_dir ('/ ' )) {
140+ if ($ storage && $ storage ->is_dir ('/ ' )) {
138141 $ dh = $ storage ->opendir ('/ ' );
139142 if (is_resource ($ dh )) {
140143 while (($ file = readdir ($ dh )) !== false ) {
141- if ($ file != '. ' and $ file != '.. ' and ($ prefix === '' || str_starts_with ($ file , $ prefix ))) {
144+ if ($ file !== '. ' && $ file !== '.. ' && ($ prefix === '' || str_starts_with ($ file , $ prefix ))) {
142145 $ storage ->unlink ('/ ' . $ file );
143146 }
144147 }
@@ -162,19 +165,19 @@ public function gc() {
162165 return null ;
163166 }
164167 while (($ file = readdir ($ dh )) !== false ) {
165- if ($ file != '. ' and $ file != '.. ' ) {
168+ if ($ file !== '. ' && $ file != = '.. ' ) {
166169 try {
167170 $ mtime = $ storage ->filemtime ('/ ' . $ file );
168171 if ($ mtime < $ now ) {
169172 $ storage ->unlink ('/ ' . $ file );
170173 }
171174 } catch (\OCP \Lock \LockedException $ e ) {
172175 // ignore locked chunks
173- \ OCP \ Server::get (LoggerInterface::class)->debug ('Could not cleanup locked chunk " ' . $ file . '" ' , ['app ' => 'core ' ]);
176+ Server::get (LoggerInterface::class)->debug ('Could not cleanup locked chunk " ' . $ file . '" ' , ['app ' => 'core ' ]);
174177 } catch (\OCP \Files \ForbiddenException $ e ) {
175- \ OCP \ Server::get (LoggerInterface::class)->debug ('Could not cleanup forbidden chunk " ' . $ file . '" ' , ['app ' => 'core ' ]);
178+ Server::get (LoggerInterface::class)->debug ('Could not cleanup forbidden chunk " ' . $ file . '" ' , ['app ' => 'core ' ]);
176179 } catch (\OCP \Files \LockNotAcquiredException $ e ) {
177- \ OCP \ Server::get (LoggerInterface::class)->debug ('Could not cleanup locked chunk " ' . $ file . '" ' , ['app ' => 'core ' ]);
180+ Server::get (LoggerInterface::class)->debug ('Could not cleanup locked chunk " ' . $ file . '" ' , ['app ' => 'core ' ]);
178181 }
179182 }
180183 }
0 commit comments