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 OCP\Files\Folder as FilesFolder; |
25
|
|
|
use OCP\Files\NotPermittedException; |
26
|
|
|
|
27
|
|
|
class Folder extends Node implements FilesFolder { |
28
|
|
|
/** |
29
|
|
|
* @inheritdoc |
30
|
|
|
*/ |
31
|
|
|
public function isSubNode($node) { |
32
|
|
|
throw new NotPermittedException(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
|
|
public function getDirectoryListing() { |
39
|
|
|
$dh = $this->storage->opendir($this->path); |
40
|
|
|
|
41
|
|
|
$entries = []; |
42
|
|
|
|
43
|
|
|
while ($entry = \readdir($dh)) { |
44
|
|
|
if ($entry === '.' || $entry === '..') { |
45
|
|
|
continue; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$entry = $this->get($entry); |
49
|
|
|
if ($entry instanceof Node) { |
50
|
|
|
$entries[] = $entry; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
\closedir($dh); |
55
|
|
|
|
56
|
|
|
return $entries; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritdoc |
61
|
|
|
*/ |
62
|
|
|
public function get($path) { |
63
|
|
|
$newPath = "$this->path/$path"; |
64
|
|
|
$type = $this->storage->filetype($newPath); |
65
|
|
|
switch ($type) { |
66
|
|
|
case 'file': return new File($this->storage, $newPath); |
67
|
|
|
case 'dir': return new Folder($this->storage, $newPath); |
68
|
|
|
} |
69
|
|
|
// TODO log error? |
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
*/ |
76
|
|
|
public function nodeExists($path) { |
77
|
|
|
return $this->storage->file_exists(\rtrim("$this->path/$path", '/')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritdoc |
82
|
|
|
*/ |
83
|
|
|
public function newFolder($path) { |
84
|
|
|
$newPath = "$this->path/$path"; |
85
|
|
|
$this->storage->mkdir($newPath); |
86
|
|
|
return new Folder($this->storage, $newPath); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritdoc |
91
|
|
|
*/ |
92
|
|
|
public function newFile($path) { |
93
|
|
|
$newPath = "$this->path/$path"; |
94
|
|
|
$this->storage->touch($newPath); |
95
|
|
|
return new File($this->storage, $newPath); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @inheritdoc |
100
|
|
|
*/ |
101
|
|
|
public function delete() { |
102
|
|
|
$this->storage->rmdir($this->path); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
|
|
public function search($query) { |
109
|
|
|
throw new NotPermittedException(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritdoc |
114
|
|
|
*/ |
115
|
|
|
public function searchByMime($mimetype) { |
116
|
|
|
throw new NotPermittedException(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @inheritdoc |
121
|
|
|
*/ |
122
|
|
|
public function searchByTag($tag, $userId) { |
123
|
|
|
throw new NotPermittedException(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
|
|
public function getById($id) { |
130
|
|
|
throw new NotPermittedException(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @inheritdoc |
135
|
|
|
*/ |
136
|
|
|
public function getFreeSpace() { |
137
|
|
|
return $this->storage->free_space($this->path); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @inheritdoc |
142
|
|
|
*/ |
143
|
|
|
public function getNonExistingName($name) { |
144
|
|
|
throw new NotPermittedException(); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|