Skip to content

Commit 119282a

Browse files
committed
fix: use nc's binary finding logic for smb
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 4f88123 commit 119282a

5 files changed

Lines changed: 37 additions & 8 deletions

File tree

apps/files_external/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
'OCA\\Files_External\\Lib\\Storage\\SMB' => $baseDir . '/../lib/Lib/Storage/SMB.php',
9797
'OCA\\Files_External\\Lib\\Storage\\StreamWrapper' => $baseDir . '/../lib/Lib/Storage/StreamWrapper.php',
9898
'OCA\\Files_External\\Lib\\Storage\\Swift' => $baseDir . '/../lib/Lib/Storage/Swift.php',
99+
'OCA\\Files_External\\Lib\\Storage\\SystemBridge' => $baseDir . '/../lib/Lib/Storage/SystemBridge.php',
99100
'OCA\\Files_External\\Lib\\VisibilityTrait' => $baseDir . '/../lib/Lib/VisibilityTrait.php',
100101
'OCA\\Files_External\\Listener\\GroupDeletedListener' => $baseDir . '/../lib/Listener/GroupDeletedListener.php',
101102
'OCA\\Files_External\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php',

apps/files_external/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class ComposerStaticInitFiles_External
111111
'OCA\\Files_External\\Lib\\Storage\\SMB' => __DIR__ . '/..' . '/../lib/Lib/Storage/SMB.php',
112112
'OCA\\Files_External\\Lib\\Storage\\StreamWrapper' => __DIR__ . '/..' . '/../lib/Lib/Storage/StreamWrapper.php',
113113
'OCA\\Files_External\\Lib\\Storage\\Swift' => __DIR__ . '/..' . '/../lib/Lib/Storage/Swift.php',
114+
'OCA\\Files_External\\Lib\\Storage\\SystemBridge' => __DIR__ . '/..' . '/../lib/Lib/Storage/SystemBridge.php',
114115
'OCA\\Files_External\\Lib\\VisibilityTrait' => __DIR__ . '/..' . '/../lib/Lib/VisibilityTrait.php',
115116
'OCA\\Files_External\\Listener\\GroupDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/GroupDeletedListener.php',
116117
'OCA\\Files_External\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php',

apps/files_external/lib/Lib/Storage/SMB.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
55
* SPDX-License-Identifier: AGPL-3.0-only
66
*/
7+
78
namespace OCA\Files_External\Lib\Storage;
89

910
use Icewind\SMB\ACL;
@@ -21,7 +22,7 @@
2122
use Icewind\SMB\Native\NativeServer;
2223
use Icewind\SMB\Options;
2324
use Icewind\SMB\ServerFactory;
24-
use Icewind\SMB\System;
25+
use Icewind\SMB\Wrapped\Server;
2526
use Icewind\Streams\CallbackWrapper;
2627
use Icewind\Streams\IteratorDirectory;
2728
use OC\Files\Filesystem;
@@ -92,7 +93,7 @@ public function __construct($params) {
9293
}
9394
$this->logger = $params['logger'];
9495
} else {
95-
$this->logger = \OC::$server->get(LoggerInterface::class);
96+
$this->logger = \OCP\Server::get(LoggerInterface::class);
9697
}
9798

9899
$options = new Options();
@@ -102,7 +103,8 @@ public function __construct($params) {
102103
$options->setTimeout($timeout);
103104
}
104105
}
105-
$serverFactory = new ServerFactory($options);
106+
$system = \OCP\Server::get(SystemBridge::class);
107+
$serverFactory = new ServerFactory($options, $system);
106108
$this->server = $serverFactory->createServer($params['host'], $auth);
107109
$this->share = $this->server->getShare(trim($params['share'], '/'));
108110

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

706706
public function test(): bool {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2024 Robin Appelman <robin@icewind.nl>
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Files_External\Lib\Storage;
10+
11+
use Icewind\SMB\System;
12+
use OCP\IBinaryFinder;
13+
14+
/**
15+
* Bridge the NC and SMB binary finding logic
16+
*/
17+
class SystemBridge extends System {
18+
public function __construct(
19+
private IBinaryFinder $binaryFinder,
20+
) {
21+
}
22+
23+
protected function getBinaryPath(string $binary): ?string {
24+
$path = $this->binaryFinder->findBinaryPath($binary);
25+
return $path !== false ? $path : null;
26+
}
27+
}

lib/public/IBinaryFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Service that find the binary path for a program.
1313
*
14-
* This interface should be injected via depency injection and must
14+
* This interface should be injected via dependency injection and must
1515
* not be implemented in applications.
1616
*
1717
* @since 25.0.0

0 commit comments

Comments
 (0)