Welcome to mirror list, hosted at ThFree Co, Russian Federation.

System.php « src « smb « icewind « 3rdparty « files_external « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3475e7a5cb6e869b442bf7b2cfe6aa68cbfce70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
 * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
 * This file is licensed under the Licensed under the MIT license:
 * http://opensource.org/licenses/MIT
 */

namespace Icewind\SMB;

use Icewind\SMB\Exception\Exception;

class System implements ISystem {
	/** @var (string|null)[] */
	private $paths = [];

	/**
	 * Get the path to a file descriptor of the current process
	 *
	 * @param int $num the file descriptor id
	 * @return string
	 * @throws Exception
	 */
	public function getFD(int $num): string {
		$folders = [
			'/proc/self/fd',
			'/dev/fd'
		];
		foreach ($folders as $folder) {
			if (file_exists($folder)) {
				return $folder . '/' . $num;
			}
		}
		throw new Exception('Cant find file descriptor path');
	}

	public function getSmbclientPath(): ?string {
		return $this->getBinaryPath('smbclient');
	}

	public function getNetPath(): ?string {
		return $this->getBinaryPath('net');
	}

	public function getSmbcAclsPath(): ?string {
		return $this->getBinaryPath('smbcacls');
	}

	public function getStdBufPath(): ?string {
		return $this->getBinaryPath('stdbuf');
	}

	public function getDatePath(): ?string {
		return $this->getBinaryPath('date');
	}

	public function libSmbclientAvailable(): bool {
		return function_exists('smbclient_state_new');
	}

	protected function getBinaryPath(string $binary): ?string {
		if (!isset($this->paths[$binary])) {
			$result = null;
			$output = [];
			exec("which $binary 2>&1", $output, $result);
			$this->paths[$binary] = $result === 0 && isset($output[0]) ? (string)$output[0] : null;
		}
		return $this->paths[$binary];
	}
}