-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make search path for BinaryFinder customizable.
This feature is important for nextcloud running on distributions like NixOS, where all the standard search paths do not exist. This fixes issue #43922 Signed-off-by: Reno Reckling <[email protected]> Signed-off-by: exi <[email protected]>
- Loading branch information
Showing
2 changed files
with
36 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
declare(strict_types = 1); | ||
/** | ||
* @copyright 2022 Carl Schwan <[email protected]> | ||
* @copyright 2024 Reno Reckling <[email protected]> | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
|
@@ -25,15 +26,28 @@ | |
use OCP\IBinaryFinder; | ||
use OCP\ICache; | ||
use OCP\ICacheFactory; | ||
use OCP\IConfig; | ||
use Symfony\Component\Process\ExecutableFinder; | ||
|
||
/** | ||
* Service that find the binary path for a program | ||
*/ | ||
class BinaryFinder implements IBinaryFinder { | ||
const DEFAULT_BINARY_SEARCH_PATHS = [ | ||
'/usr/local/sbin', | ||
'/usr/local/bin', | ||
'/usr/sbin', | ||
'/usr/bin', | ||
'/sbin', | ||
'/bin', | ||
'/opt/bin', | ||
]; | ||
private ICache $cache; | ||
|
||
public function __construct(ICacheFactory $cacheFactory) { | ||
public function __construct( | ||
ICacheFactory $cacheFactory, | ||
private IConfig $config | ||
) { | ||
$this->cache = $cacheFactory->createLocal('findBinaryPath'); | ||
} | ||
|
||
|
@@ -51,15 +65,10 @@ public function findBinaryPath(string $program) { | |
if (\OCP\Util::isFunctionEnabled('exec')) { | ||
$exeSniffer = new ExecutableFinder(); | ||
// Returns null if nothing is found | ||
$result = $exeSniffer->find($program, null, [ | ||
'/usr/local/sbin', | ||
'/usr/local/bin', | ||
'/usr/sbin', | ||
'/usr/bin', | ||
'/sbin', | ||
'/bin', | ||
'/opt/bin', | ||
]); | ||
$result = $exeSniffer->find( | ||
$program, | ||
null, | ||
$this->config->getSystemValue('binary_search_paths', self::DEFAULT_BINARY_SEARCH_PATHS)); | ||
if ($result === null) { | ||
$result = false; | ||
} | ||
|