|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OC\Files\Storage; |
|
23
|
|
|
|
|
24
|
|
|
use OC\Files\Node\AbstractNode; |
|
25
|
|
|
use OCP\Files\NotFoundException; |
|
26
|
|
|
use OCP\Files\Storage\IStorage; |
|
27
|
|
|
use OC\Files\Storage\Folder as StorageFolder; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class Node |
|
31
|
|
|
* |
|
32
|
|
|
* The Storage/Node classes are intended to work directly on the storage, |
|
33
|
|
|
* bypassing any updates to the metadata in the filecache, which is expensive |
|
34
|
|
|
* and not needed for avatars, thumbnails and maybe other things. |
|
35
|
|
|
* |
|
36
|
|
|
* @package OC\Files\Storage |
|
37
|
|
|
*/ |
|
38
|
|
|
abstract class Node extends AbstractNode { |
|
39
|
|
|
|
|
40
|
|
|
/** @var IStorage */ |
|
41
|
|
|
protected $storage; |
|
42
|
|
|
|
|
43
|
|
|
/** @var string $path relative to the storage root */ |
|
44
|
|
|
protected $path; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param IStorage $storage |
|
48
|
|
|
* @param $path |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(IStorage $storage, $path) { |
|
51
|
|
|
$this->storage = $storage; |
|
52
|
|
|
$this->path = $path; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getMimetype() { |
|
59
|
|
|
return $this->storage->getMimeType($this->path); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritdoc |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getMimePart() { |
|
66
|
|
|
return \explode('/', $this->getMimetype(), 2)[0]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritdoc |
|
71
|
|
|
*/ |
|
72
|
|
|
public function isEncrypted() { |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @inheritdoc |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getType() { |
|
80
|
|
|
$type = $this->storage->filetype($this->path); |
|
81
|
|
|
switch ($type) { |
|
82
|
|
|
case 'file': return \OCP\Files\FileInfo::TYPE_FILE; |
|
83
|
|
|
case 'dir': return \OCP\Files\FileInfo::TYPE_FOLDER; |
|
84
|
|
|
case 'link': //TODO readlink and check it if path is in same storage |
|
85
|
|
|
default: |
|
86
|
|
|
throw new \UnexpectedValueException("filetype $type not supported "); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @inheritdoc |
|
92
|
|
|
*/ |
|
93
|
|
|
public function isCreatable() { |
|
94
|
|
|
return $this->storage->isCreatable($this->path); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritdoc |
|
99
|
|
|
*/ |
|
100
|
|
|
public function isShared() { |
|
101
|
|
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @inheritdoc |
|
106
|
|
|
*/ |
|
107
|
|
|
public function touch($mtime = null) { |
|
108
|
|
|
$this->storage->touch($this->path, $mtime); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @inheritdoc |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getStorage() { |
|
115
|
|
|
return $this->storage; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @inheritdoc |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getInternalPath() { |
|
122
|
|
|
return $this->path; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @inheritdoc |
|
127
|
|
|
*/ |
|
128
|
|
|
public function stat() { |
|
129
|
|
|
return $this->storage->stat($this->path); |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @inheritdoc |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getMTime() { |
|
136
|
|
|
return $this->storage->filemtime($this->path); |
|
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @inheritdoc |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getSize() { |
|
143
|
|
|
return $this->storage->filesize($this->path); |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @inheritdoc |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getEtag() { |
|
150
|
|
|
return $this->storage->getETag($this->path); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @inheritdoc |
|
155
|
|
|
*/ |
|
156
|
|
|
public function getPermissions() { |
|
157
|
|
|
return $this->storage->getPermissions($this->path); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @inheritdoc |
|
162
|
|
|
*/ |
|
163
|
|
|
public function isReadable() { |
|
164
|
|
|
return $this->storage->isReadable($this->path); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @inheritdoc |
|
169
|
|
|
*/ |
|
170
|
|
|
public function isUpdateable() { |
|
171
|
|
|
return $this->storage->isUpdatable($this->path); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @inheritdoc |
|
176
|
|
|
*/ |
|
177
|
|
|
public function isDeletable() { |
|
178
|
|
|
return $this->storage->isDeletable($this->path); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @inheritdoc |
|
183
|
|
|
*/ |
|
184
|
|
|
public function isShareable() { |
|
185
|
|
|
return false; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @inheritdoc |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getParent() { |
|
192
|
|
|
$parent = \dirname($this->path); |
|
193
|
|
|
if ($parent === '' || $parent === '.') { |
|
194
|
|
|
throw new NotFoundException($parent); |
|
195
|
|
|
} |
|
196
|
|
|
return new StorageFolder($this->storage, $parent); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @inheritdoc |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getName() { |
|
203
|
|
|
return \basename($this->path); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|