|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Robin Appelman <[email protected]> |
|
6
|
|
|
* @author Semih Serhat Karakaya <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license AGPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace OC\Files\Config; |
|
24
|
|
|
|
|
25
|
|
|
use OC\Files\Filesystem; |
|
26
|
|
|
use OCP\Files\Config\ICachedMountInfo; |
|
27
|
|
|
use OCP\Files\Node; |
|
28
|
|
|
use OCP\IUser; |
|
29
|
|
|
|
|
30
|
|
|
class CachedMountInfo implements ICachedMountInfo { |
|
31
|
|
|
/** |
|
32
|
|
|
* @var IUser |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $user; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var int |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $storageId; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var int |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $rootId; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $mountPoint; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var int|null |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $mountId; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $rootInternalPath; |
|
60
|
|
|
|
|
61
|
|
|
/** @var string */ |
|
62
|
|
|
protected $mountProvider; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* CachedMountInfo constructor. |
|
66
|
|
|
* |
|
67
|
|
|
* @param IUser $user |
|
68
|
|
|
* @param int $storageId |
|
69
|
|
|
* @param int $rootId |
|
70
|
|
|
* @param string $mountPoint |
|
71
|
|
|
* @param int|null $mountId |
|
72
|
|
|
* @param string $rootInternalPath |
|
73
|
|
|
*/ |
|
74
|
|
|
public function __construct( |
|
75
|
|
|
IUser $user, |
|
76
|
|
|
int $storageId, |
|
77
|
|
|
int $rootId, |
|
78
|
|
|
string $mountPoint, |
|
79
|
|
|
string $mountProvider, |
|
80
|
|
|
int $mountId = null, |
|
81
|
|
|
string $rootInternalPath = '' |
|
82
|
|
|
) { |
|
83
|
|
|
$this->user = $user; |
|
84
|
|
|
$this->storageId = $storageId; |
|
85
|
|
|
$this->rootId = $rootId; |
|
86
|
|
|
$this->mountPoint = $mountPoint; |
|
87
|
|
|
$this->mountId = $mountId; |
|
88
|
|
|
$this->rootInternalPath = $rootInternalPath; |
|
89
|
|
|
if (strlen($mountProvider) > 128) { |
|
90
|
|
|
throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters"); |
|
91
|
|
|
} |
|
92
|
|
|
$this->mountProvider = $mountProvider; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return IUser |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getUser() { |
|
99
|
|
|
return $this->user; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return int the numeric storage id of the mount |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getStorageId() { |
|
106
|
|
|
return $this->storageId; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return int the fileid of the root of the mount |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getRootId() { |
|
113
|
|
|
return $this->rootId; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return Node the root node of the mount |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getMountPointNode() { |
|
120
|
|
|
// TODO injection etc |
|
121
|
|
|
Filesystem::initMountPoints($this->getUser()->getUID()); |
|
122
|
|
|
$userNode = \OC::$server->getUserFolder($this->getUser()->getUID()); |
|
123
|
|
|
$nodes = $userNode->getParent()->getById($this->getRootId()); |
|
124
|
|
|
if (count($nodes) > 0) { |
|
125
|
|
|
return $nodes[0]; |
|
126
|
|
|
} else { |
|
127
|
|
|
return null; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string the mount point of the mount for the user |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getMountPoint() { |
|
135
|
|
|
return $this->mountPoint; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Get the id of the configured mount |
|
140
|
|
|
* |
|
141
|
|
|
* @return int|null mount id or null if not applicable |
|
142
|
|
|
* @since 9.1.0 |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getMountId() { |
|
145
|
|
|
return $this->mountId; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Get the internal path (within the storage) of the root of the mount |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getRootInternalPath() { |
|
154
|
|
|
return $this->rootInternalPath; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function getMountProvider(): string { |
|
158
|
|
|
return $this->mountProvider; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|