diff --git a/lib/BinExt.php b/lib/BinExt.php index 768e8ee9..21d532d7 100644 --- a/lib/BinExt.php +++ b/lib/BinExt.php @@ -38,6 +38,14 @@ class BinExt throw new \Exception("failed to find exiftool temp binary {$target}"); } + /** Get the name for a binary */ + public static function getName(string $name, string $version = ''): string + { + $id = Util::getInstanceId(); + + return empty($version) ? "{$name}-{$id}" : "{$name}-{$id}-{$version}"; + } + /** Test configured exiftool binary */ public static function testExiftool(): bool { @@ -61,7 +69,7 @@ class BinExt { $path = Util::getSystemConfig('memories.exiftool'); - return self::getTempBin($path, 'exiftool-'.self::EXIFTOOL_VER); + return self::getTempBin($path, self::getName('exiftool', self::EXIFTOOL_VER)); } /** Get path to exiftool binary for proc_open */ @@ -146,7 +154,7 @@ class BinExt } // Add instance ID to path - $tmpPath .= Util::getSystemConfig('instanceid', 'default'); + $tmpPath .= Util::getInstanceId(); return array_merge($env, [ 'bind' => Util::getSystemConfig('memories.vod.bind'), @@ -161,7 +169,9 @@ class BinExt */ public static function getGoVodBin() { - return self::getTempBin(Util::getSystemConfig('memories.vod.path'), 'go-vod-'.self::GOVOD_VER); + $path = Util::getSystemConfig('memories.vod.path'); + + return self::getTempBin($path, self::getName('go-vod', self::GOVOD_VER)); } /** @@ -170,6 +180,14 @@ class BinExt */ public static function startGoVod() { + // Check if disabled + if (Util::getSystemConfig('memories.vod.disable')) { + // Make sure it's dead, in case the user just disabled it + Util::pkill(self::getName('go-vod')); + + return; + } + // Check if external if (Util::getSystemConfig('memories.vod.external')) { self::configureGoVod(); @@ -206,7 +224,7 @@ class BinExt file_put_contents($configFile, json_encode($env, JSON_PRETTY_PRINT)); // Kill the transcoder in case it's running - \OCA\Memories\Util::pkill($transcoder); + Util::pkill(self::getName('go-vod')); // Start transcoder shell_exec("nohup {$transcoder} {$configFile} >> '{$logFile}' 2>&1 & > /dev/null"); @@ -239,6 +257,11 @@ class BinExt /** Test the go-vod instance that is running */ public static function testGoVod(): bool { + // Check if disabled + if (Util::getSystemConfig('memories.vod.disable')) { + throw new \Exception('Transcoding is disabled'); + } + // TODO: check data mount; ignoring the result of the file for now $testfile = realpath(__DIR__.'/../exiftest.jpg'); diff --git a/lib/Migration/Repair.php b/lib/Migration/Repair.php index f0691328..42cde0a5 100644 --- a/lib/Migration/Repair.php +++ b/lib/Migration/Repair.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace OCA\Memories\Migration; +use OCA\Memories\BinExt; +use OCA\Memories\Util; use OCP\IConfig; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -25,8 +27,8 @@ class Repair implements IRepairStep public function run(IOutput $output): void { // kill any instances of go-vod and exiftool - \OCA\Memories\Util::pkill('go-vod'); - \OCA\Memories\Util::pkill('exiftool'); + Util::pkill(BinExt::getName('go-vod')); + Util::pkill(BinExt::getName('exiftool')); // detect exiftool if ($path = \OCA\Memories\BinExt::detectExiftool()) { diff --git a/lib/Util.php b/lib/Util.php index dedb927f..8d579a9e 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -285,13 +285,22 @@ class Util /** * Get a system config key with the correct default. * - * @param null|mixed $default + * @param string $key System config key + * @param null|mixed $default Default value + * @param bool $force Do not check if the key is valid */ - public static function getSystemConfig(string $key, $default = null) + public static function getSystemConfig(string $key, $default = null, bool $force = false) { $config = \OC::$server->get(\OCP\IConfig::class); - return $config->getSystemValue($key, $default ?? self::systemConfigDefaults()[$key]); + $defaults = self::systemConfigDefaults(); + if (!$force) { + if (!\array_key_exists($key, $defaults)) { + throw new \InvalidArgumentException("Invalid system config key: {$key}"); + } + } + + return $config->getSystemValue($key, $default ?? $defaults[$key]); } /** @@ -383,6 +392,14 @@ class Util ]; } + /** + * Get the instance ID for this instance. + */ + public static function getInstanceId(): string + { + return self::getSystemConfig('instanceid', 'default', true); + } + /** * Kill all instances of a process by name. * Similar to pkill, which may not be available on all systems.