Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use nc's binary finding logic for smb #48421

Merged
merged 1 commit into from
Oct 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
'OCA\\Files_External\\Lib\\Storage\\SMB' => $baseDir . '/../lib/Lib/Storage/SMB.php',
'OCA\\Files_External\\Lib\\Storage\\StreamWrapper' => $baseDir . '/../lib/Lib/Storage/StreamWrapper.php',
'OCA\\Files_External\\Lib\\Storage\\Swift' => $baseDir . '/../lib/Lib/Storage/Swift.php',
'OCA\\Files_External\\Lib\\Storage\\SystemBridge' => $baseDir . '/../lib/Lib/Storage/SystemBridge.php',
'OCA\\Files_External\\Lib\\VisibilityTrait' => $baseDir . '/../lib/Lib/VisibilityTrait.php',
'OCA\\Files_External\\Listener\\GroupDeletedListener' => $baseDir . '/../lib/Listener/GroupDeletedListener.php',
'OCA\\Files_External\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php',
Expand Down
1 change: 1 addition & 0 deletions apps/files_external/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ComposerStaticInitFiles_External
'OCA\\Files_External\\Lib\\Storage\\SMB' => __DIR__ . '/..' . '/../lib/Lib/Storage/SMB.php',
'OCA\\Files_External\\Lib\\Storage\\StreamWrapper' => __DIR__ . '/..' . '/../lib/Lib/Storage/StreamWrapper.php',
'OCA\\Files_External\\Lib\\Storage\\Swift' => __DIR__ . '/..' . '/../lib/Lib/Storage/Swift.php',
'OCA\\Files_External\\Lib\\Storage\\SystemBridge' => __DIR__ . '/..' . '/../lib/Lib/Storage/SystemBridge.php',
'OCA\\Files_External\\Lib\\VisibilityTrait' => __DIR__ . '/..' . '/../lib/Lib/VisibilityTrait.php',
'OCA\\Files_External\\Listener\\GroupDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/GroupDeletedListener.php',
'OCA\\Files_External\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php',
Expand Down
14 changes: 7 additions & 7 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCA\Files_External\Lib\Storage;

use Icewind\SMB\ACL;
Expand All @@ -21,7 +22,7 @@
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Options;
use Icewind\SMB\ServerFactory;
use Icewind\SMB\System;
use Icewind\SMB\Wrapped\Server;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\Filesystem;
Expand Down Expand Up @@ -92,7 +93,7 @@ public function __construct($params) {
}
$this->logger = $params['logger'];
} else {
$this->logger = \OC::$server->get(LoggerInterface::class);
$this->logger = \OCP\Server::get(LoggerInterface::class);
}

$options = new Options();
Expand All @@ -102,7 +103,8 @@ public function __construct($params) {
$options->setTimeout($timeout);
}
}
$serverFactory = new ServerFactory($options);
$system = \OCP\Server::get(SystemBridge::class);
$serverFactory = new ServerFactory($options, $system);
$this->server = $serverFactory->createServer($params['host'], $auth);
$this->share = $this->server->getShare(trim($params['share'], '/'));

Expand Down Expand Up @@ -697,10 +699,8 @@ public function isDeletable($path): bool {
* check if smbclient is installed
*/
public static function checkDependencies(): array|bool {
return (
(bool)\OC_Helper::findBinaryPath('smbclient')
|| NativeServer::available(new System())
) ? true : ['smbclient'];
$system = \OCP\Server::get(SystemBridge::class);
return Server::available($system) || NativeServer::available($system) ?: ['smbclient'];
}

public function test(): bool {
Expand Down
27 changes: 27 additions & 0 deletions apps/files_external/lib/Lib/Storage/SystemBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Robin Appelman <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files_External\Lib\Storage;

use Icewind\SMB\System;
use OCP\IBinaryFinder;

/**
* Bridge the NC and SMB binary finding logic
*/
class SystemBridge extends System {
public function __construct(
private IBinaryFinder $binaryFinder,
) {
}

protected function getBinaryPath(string $binary): ?string {
$path = $this->binaryFinder->findBinaryPath($binary);
return $path !== false ? $path : null;
}
}
2 changes: 1 addition & 1 deletion lib/public/IBinaryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Service that find the binary path for a program.
*
* This interface should be injected via depency injection and must
* This interface should be injected via dependency injection and must
* not be implemented in applications.
*
* @since 25.0.0
Expand Down
Loading