diff options
author | Robin McCorkell <rmccorkell@owncloud.com> | 2015-09-11 12:44:53 +0100 |
---|---|---|
committer | Robin McCorkell <rmccorkell@owncloud.com> | 2015-09-11 12:44:53 +0100 |
commit | 188d0e09b857e607b57b7686e95bbf0502359c2b (patch) | |
tree | dcd1fd2c38a81a7b99050d997092ab557011ce35 | |
parent | b8f7d85570f01a0d1baf3082b0d84b6bafc8ae8c (diff) | |
download | nextcloud-server-188d0e09b857e607b57b7686e95bbf0502359c2b.tar.gz nextcloud-server-188d0e09b857e607b57b7686e95bbf0502359c2b.zip |
Add reset method to mimetype loader
Used to solve concurrency issues
-rw-r--r-- | lib/private/files/cache/scanner.php | 2 | ||||
-rw-r--r-- | lib/private/files/type/loader.php | 8 | ||||
-rw-r--r-- | lib/public/files/imimetypeloader.php | 7 | ||||
-rw-r--r-- | tests/lib/repair/repairmimetypes.php | 15 |
4 files changed, 19 insertions, 13 deletions
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index f76ef5ba0dd..fb60ee5aa53 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -377,7 +377,7 @@ class Scanner extends BasicEmitter { // inserted mimetypes but those weren't available yet inside the transaction // To make sure to have the updated mime types in such cases, // we reload them here - $this->cache->loadMimetypes(); + \OC::$server->getMimeTypeLoader()->reset(); } foreach ($childQueue as $child => $childData) { diff --git a/lib/private/files/type/loader.php b/lib/private/files/type/loader.php index df893306615..78bfcf60bff 100644 --- a/lib/private/files/type/loader.php +++ b/lib/private/files/type/loader.php @@ -97,6 +97,14 @@ class Loader implements IMimeTypeLoader { } /** + * Clear all loaded mimetypes, allow for re-loading + */ + public function reset() { + $this->mimetypes = []; + $this->mimetypeIds = []; + } + + /** * Store a mimetype in the DB * * @param string $mimetype diff --git a/lib/public/files/imimetypeloader.php b/lib/public/files/imimetypeloader.php index 24937ea9b86..6d00c4a0b31 100644 --- a/lib/public/files/imimetypeloader.php +++ b/lib/public/files/imimetypeloader.php @@ -56,4 +56,11 @@ interface IMimeTypeLoader { * @since 8.2.0 */ public function exists($mimetype); + + /** + * Clear all loaded mimetypes, allow for re-loading + * + * @since 8.2.0 + */ + public function reset(); } diff --git a/tests/lib/repair/repairmimetypes.php b/tests/lib/repair/repairmimetypes.php index 76d4d7cc656..da36e7de58a 100644 --- a/tests/lib/repair/repairmimetypes.php +++ b/tests/lib/repair/repairmimetypes.php @@ -24,13 +24,7 @@ class RepairMimeTypes extends \Test\TestCase { parent::setUp(); $this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader(); - $this->mimetypeLoader = $this->getMockBuilder('\OC\Files\Type\Loader') - ->setConstructorArgs([\OC::$server->getDatabaseConnection()]) - ->setMethods(null) - ->getMock(); - \OC::$server->registerService('MimeTypeLoader', function ($c) { - return $this->mimetypeLoader; - }); + $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->storage = new \OC\Files\Storage\Temporary([]); $this->repair = new \OC\Repair\RepairMimeTypes(); @@ -42,16 +36,13 @@ class RepairMimeTypes extends \Test\TestCase { \OC_DB::executeAudited($sql, [$this->storage->getId()]); $this->clearMimeTypes(); - \OC::$server->registerService('MimeTypeLoader', function($c) { - return $this->savedMimetypeLoader; - }); - parent::tearDown(); } private function clearMimeTypes() { $sql = 'DELETE FROM `*PREFIX*mimetypes`'; \OC_DB::executeAudited($sql); + $this->mimetypeLoader->reset(); } private function addEntries($entries) { @@ -97,7 +88,7 @@ class RepairMimeTypes extends \Test\TestCase { $this->repair->run(); // force mimetype reload - self::invokePrivate($this->mimetypeLoader, 'loadMimetypes'); + $this->mimetypeLoader->reset(); $this->checkEntries($fixedMimeTypes); } |