diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Config.php | 7 | ||||
-rw-r--r-- | lib/private/Preview/IMagickSupport.php | 40 | ||||
-rw-r--r-- | lib/private/PreviewManager.php | 14 | ||||
-rw-r--r-- | lib/private/Server.php | 4 | ||||
-rw-r--r-- | lib/public/AppFramework/Controller.php | 3 |
7 files changed, 63 insertions, 7 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 6e0934c8fa1..8f4579bdd9c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1391,6 +1391,7 @@ return array( 'OC\\Preview\\Generator' => $baseDir . '/lib/private/Preview/Generator.php', 'OC\\Preview\\GeneratorHelper' => $baseDir . '/lib/private/Preview/GeneratorHelper.php', 'OC\\Preview\\HEIC' => $baseDir . '/lib/private/Preview/HEIC.php', + 'OC\\Preview\\IMagickSupport' => $baseDir . '/lib/private/Preview/IMagickSupport.php', 'OC\\Preview\\Illustrator' => $baseDir . '/lib/private/Preview/Illustrator.php', 'OC\\Preview\\Image' => $baseDir . '/lib/private/Preview/Image.php', 'OC\\Preview\\Imaginary' => $baseDir . '/lib/private/Preview/Imaginary.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 50aaa84ae77..21550e558a5 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1424,6 +1424,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Preview\\Generator' => __DIR__ . '/../../..' . '/lib/private/Preview/Generator.php', 'OC\\Preview\\GeneratorHelper' => __DIR__ . '/../../..' . '/lib/private/Preview/GeneratorHelper.php', 'OC\\Preview\\HEIC' => __DIR__ . '/../../..' . '/lib/private/Preview/HEIC.php', + 'OC\\Preview\\IMagickSupport' => __DIR__ . '/../../..' . '/lib/private/Preview/IMagickSupport.php', 'OC\\Preview\\Illustrator' => __DIR__ . '/../../..' . '/lib/private/Preview/Illustrator.php', 'OC\\Preview\\Image' => __DIR__ . '/../../..' . '/lib/private/Preview/Image.php', 'OC\\Preview\\Imaginary' => __DIR__ . '/../../..' . '/lib/private/Preview/Imaginary.php', diff --git a/lib/private/Config.php b/lib/private/Config.php index ba3b8c6fe4d..7308a3769df 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -285,6 +285,13 @@ class Config { 'This can usually be fixed by giving the webserver write access to the config directory.'); } + // Never write file back if disk space should be too low + $df = disk_free_space($this->configDir); + $size = strlen($content) + 10240; + if ($df !== false && (int)$df < $size) { + throw new \Exception($this->configDir . " does not have enough space for writing the config file! Not writing it back!"); + } + // Try to acquire a file lock if (!flock($filePointer, LOCK_EX)) { throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath)); diff --git a/lib/private/Preview/IMagickSupport.php b/lib/private/Preview/IMagickSupport.php new file mode 100644 index 00000000000..e22ae93ab94 --- /dev/null +++ b/lib/private/Preview/IMagickSupport.php @@ -0,0 +1,40 @@ +<?php + +namespace OC\Preview; + +use OCP\ICache; +use OCP\ICacheFactory; + +class IMagickSupport { + private ICache $cache; + private ?\Imagick $imagick; + + public function __construct(ICacheFactory $cacheFactory) { + $this->cache = $cacheFactory->createLocal('imagick'); + + if (extension_loaded('imagick')) { + $this->imagick = new \Imagick(); + } else { + $this->imagick = null; + } + } + + public function hasExtension(): bool { + return !is_null($this->imagick); + } + + public function supportsFormat(string $format): bool { + if (is_null($this->imagick)) { + return false; + } + + $cached = $this->cache->get($format); + if (!is_null($cached)) { + return $cached; + } + + $formatSupported = count($this->imagick->queryFormats($format)) === 1; + $this->cache->set($format, $cached); + return $formatSupported; + } +} diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 367f0c1c057..dd6b6ba8ee1 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -33,6 +33,7 @@ namespace OC; use OC\AppFramework\Bootstrap\Coordinator; use OC\Preview\Generator; use OC\Preview\GeneratorHelper; +use OC\Preview\IMagickSupport; use OCP\AppFramework\QueryException; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; @@ -73,6 +74,7 @@ class PreviewManager implements IPreview { private array $loadedBootstrapProviders = []; private IServerContainer $container; private IBinaryFinder $binaryFinder; + private IMagickSupport $imagickSupport; public function __construct( IConfig $config, @@ -84,7 +86,8 @@ class PreviewManager implements IPreview { ?string $userId, Coordinator $bootstrapCoordinator, IServerContainer $container, - IBinaryFinder $binaryFinder + IBinaryFinder $binaryFinder, + IMagickSupport $imagickSupport ) { $this->config = $config; $this->rootFolder = $rootFolder; @@ -96,6 +99,7 @@ class PreviewManager implements IPreview { $this->bootstrapCoordinator = $bootstrapCoordinator; $this->container = $container; $this->binaryFinder = $binaryFinder; + $this->imagickSupport = $imagickSupport; } /** @@ -368,9 +372,7 @@ class PreviewManager implements IPreview { $this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes()); // SVG, Office and Bitmap require imagick - if (extension_loaded('imagick')) { - $checkImagick = new \Imagick(); - + if ($this->imagickSupport->hasExtension()) { $imagickProviders = [ 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], @@ -390,12 +392,12 @@ class PreviewManager implements IPreview { continue; } - if (count($checkImagick->queryFormats($queryFormat)) === 1) { + if ($this->imagickSupport->supportsFormat($queryFormat)) { $this->registerCoreProvider($class, $provider['mimetype']); } } - if (count($checkImagick->queryFormats('PDF')) === 1) { + if ($this->imagickSupport->supportsFormat('PDF')) { // Office requires openoffice or libreoffice $officeBinary = $this->config->getSystemValue('preview_libreoffice_path', null); if (!is_string($officeBinary)) { diff --git a/lib/private/Server.php b/lib/private/Server.php index 4ade6bf7c1c..35f63686457 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -127,6 +127,7 @@ use OC\Metadata\MetadataManager; use OC\Notification\Manager; use OC\OCS\DiscoveryService; use OC\Preview\GeneratorHelper; +use OC\Preview\IMagickSupport; use OC\Remote\Api\ApiFactory; use OC\Remote\InstanceFactory; use OC\RichObjectStrings\Validator; @@ -338,7 +339,8 @@ class Server extends ServerContainer implements IServerContainer { $c->get(ISession::class)->get('user_id'), $c->get(Coordinator::class), $c->get(IServerContainer::class), - $c->get(IBinaryFinder::class) + $c->get(IBinaryFinder::class), + $c->get(IMagickSupport::class) ); }); /** @deprecated 19.0.0 */ diff --git a/lib/public/AppFramework/Controller.php b/lib/public/AppFramework/Controller.php index 89cfd2e55fc..e8500d5ae1a 100644 --- a/lib/public/AppFramework/Controller.php +++ b/lib/public/AppFramework/Controller.php @@ -91,6 +91,9 @@ abstract class Controller { if ($data->getLastModified() !== null) { $response->setLastModified($data->getLastModified()); } + if ($data->isThrottled()) { + $response->throttle($data->getThrottleMetadata()); + } return $response; } |