Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/private/Files/Type/Detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OC\Files\Type;

use OCP\Files\IMimeTypeDetector;
use OCP\IBinaryFinder;
use OCP\ITempManager;
use OCP\IURLGenerator;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -225,11 +226,13 @@ public function detectContent(string $path): string {
}
}

if (\OC_Helper::canExecute('file')) {
$binaryFinder = \OCP\Server::get(IBinaryFinder::class);
$program = $binaryFinder->findBinaryPath('file');
if ($program !== false) {
// it looks like we have a 'file' command,
// lets see if it does have mime support
$path = escapeshellarg($path);
$fp = popen("test -f $path && file -b --mime-type $path", 'r');
$fp = popen("test -f $path && $program -b --mime-type $path", 'r');
if ($fp !== false) {
$mimeType = fgets($fp);
pclose($fp);
Expand Down
1 change: 1 addition & 0 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public static function getFileTemplateManager() {
* @internal param string $program name
* @internal param string $optional search path, defaults to $PATH
* @return bool true if executable program found in path
* @deprecated 32.0.0 use the \OCP\IBinaryFinder
*/
public static function canExecute($name, $path = false) {
// path defaults to PATH from environment if not set
Expand Down
Loading