@@ -32,156 +32,156 @@ |
||
32 | 32 | |
33 | 33 | class SimpleFile implements ISimpleFile { |
34 | 34 | |
35 | - /** @var File $file */ |
|
36 | - private $file; |
|
37 | - |
|
38 | - /** |
|
39 | - * File constructor. |
|
40 | - * |
|
41 | - * @param File $file |
|
42 | - */ |
|
43 | - public function __construct(File $file) { |
|
44 | - $this->file = $file; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Get the name |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function getName() { |
|
53 | - return $this->file->getName(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get the size in bytes |
|
58 | - * |
|
59 | - * @return int |
|
60 | - */ |
|
61 | - public function getSize() { |
|
62 | - return $this->file->getSize(); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the ETag |
|
67 | - * |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getETag() { |
|
71 | - return $this->file->getEtag(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the last modification time |
|
76 | - * |
|
77 | - * @return int |
|
78 | - */ |
|
79 | - public function getMTime() { |
|
80 | - return $this->file->getMTime(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get the content |
|
85 | - * |
|
86 | - * @throws NotPermittedException |
|
87 | - * @throws NotFoundException |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getContent() { |
|
91 | - $result = $this->file->getContent(); |
|
92 | - |
|
93 | - if ($result === false) { |
|
94 | - $this->checkFile(); |
|
95 | - } |
|
96 | - |
|
97 | - return $result; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Overwrite the file |
|
102 | - * |
|
103 | - * @param string|resource $data |
|
104 | - * @throws NotPermittedException |
|
105 | - * @throws NotFoundException |
|
106 | - */ |
|
107 | - public function putContent($data) { |
|
108 | - try { |
|
109 | - return $this->file->putContent($data); |
|
110 | - } catch (NotFoundException $e) { |
|
111 | - $this->checkFile(); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Sometimes there are some issues with the AppData. Most of them are from |
|
117 | - * user error. But we should handle them gracefull anyway. |
|
118 | - * |
|
119 | - * If for some reason the current file can't be found. We remove it. |
|
120 | - * Then traverse up and check all folders if they exists. This so that the |
|
121 | - * next request will have a valid appdata structure again. |
|
122 | - * |
|
123 | - * @throws NotFoundException |
|
124 | - */ |
|
125 | - private function checkFile() { |
|
126 | - $cur = $this->file; |
|
127 | - |
|
128 | - while ($cur->stat() === false) { |
|
129 | - $parent = $cur->getParent(); |
|
130 | - try { |
|
131 | - $cur->delete(); |
|
132 | - } catch (NotFoundException $e) { |
|
133 | - // Just continue then |
|
134 | - } |
|
135 | - $cur = $parent; |
|
136 | - } |
|
137 | - |
|
138 | - if ($cur !== $this->file) { |
|
139 | - throw new NotFoundException('File does not exist'); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Delete the file |
|
146 | - * |
|
147 | - * @throws NotPermittedException |
|
148 | - */ |
|
149 | - public function delete() { |
|
150 | - $this->file->delete(); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Get the MimeType |
|
155 | - * |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function getMimeType() { |
|
159 | - return $this->file->getMimeType(); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen |
|
164 | - * |
|
165 | - * @return resource |
|
166 | - * @throws \OCP\Files\NotPermittedException |
|
167 | - * @since 14.0.0 |
|
168 | - */ |
|
169 | - public function read() { |
|
170 | - return $this->file->fopen('r'); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen |
|
175 | - * |
|
176 | - * @return resource |
|
177 | - * @throws \OCP\Files\NotPermittedException |
|
178 | - * @since 14.0.0 |
|
179 | - */ |
|
180 | - public function write() { |
|
181 | - return $this->file->fopen('w'); |
|
182 | - } |
|
183 | - |
|
184 | - public function getId(): int { |
|
185 | - return $this->file->getId(); |
|
186 | - } |
|
35 | + /** @var File $file */ |
|
36 | + private $file; |
|
37 | + |
|
38 | + /** |
|
39 | + * File constructor. |
|
40 | + * |
|
41 | + * @param File $file |
|
42 | + */ |
|
43 | + public function __construct(File $file) { |
|
44 | + $this->file = $file; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Get the name |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function getName() { |
|
53 | + return $this->file->getName(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get the size in bytes |
|
58 | + * |
|
59 | + * @return int |
|
60 | + */ |
|
61 | + public function getSize() { |
|
62 | + return $this->file->getSize(); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the ETag |
|
67 | + * |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getETag() { |
|
71 | + return $this->file->getEtag(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the last modification time |
|
76 | + * |
|
77 | + * @return int |
|
78 | + */ |
|
79 | + public function getMTime() { |
|
80 | + return $this->file->getMTime(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get the content |
|
85 | + * |
|
86 | + * @throws NotPermittedException |
|
87 | + * @throws NotFoundException |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getContent() { |
|
91 | + $result = $this->file->getContent(); |
|
92 | + |
|
93 | + if ($result === false) { |
|
94 | + $this->checkFile(); |
|
95 | + } |
|
96 | + |
|
97 | + return $result; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Overwrite the file |
|
102 | + * |
|
103 | + * @param string|resource $data |
|
104 | + * @throws NotPermittedException |
|
105 | + * @throws NotFoundException |
|
106 | + */ |
|
107 | + public function putContent($data) { |
|
108 | + try { |
|
109 | + return $this->file->putContent($data); |
|
110 | + } catch (NotFoundException $e) { |
|
111 | + $this->checkFile(); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Sometimes there are some issues with the AppData. Most of them are from |
|
117 | + * user error. But we should handle them gracefull anyway. |
|
118 | + * |
|
119 | + * If for some reason the current file can't be found. We remove it. |
|
120 | + * Then traverse up and check all folders if they exists. This so that the |
|
121 | + * next request will have a valid appdata structure again. |
|
122 | + * |
|
123 | + * @throws NotFoundException |
|
124 | + */ |
|
125 | + private function checkFile() { |
|
126 | + $cur = $this->file; |
|
127 | + |
|
128 | + while ($cur->stat() === false) { |
|
129 | + $parent = $cur->getParent(); |
|
130 | + try { |
|
131 | + $cur->delete(); |
|
132 | + } catch (NotFoundException $e) { |
|
133 | + // Just continue then |
|
134 | + } |
|
135 | + $cur = $parent; |
|
136 | + } |
|
137 | + |
|
138 | + if ($cur !== $this->file) { |
|
139 | + throw new NotFoundException('File does not exist'); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Delete the file |
|
146 | + * |
|
147 | + * @throws NotPermittedException |
|
148 | + */ |
|
149 | + public function delete() { |
|
150 | + $this->file->delete(); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Get the MimeType |
|
155 | + * |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function getMimeType() { |
|
159 | + return $this->file->getMimeType(); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen |
|
164 | + * |
|
165 | + * @return resource |
|
166 | + * @throws \OCP\Files\NotPermittedException |
|
167 | + * @since 14.0.0 |
|
168 | + */ |
|
169 | + public function read() { |
|
170 | + return $this->file->fopen('r'); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen |
|
175 | + * |
|
176 | + * @return resource |
|
177 | + * @throws \OCP\Files\NotPermittedException |
|
178 | + * @since 14.0.0 |
|
179 | + */ |
|
180 | + public function write() { |
|
181 | + return $this->file->fopen('w'); |
|
182 | + } |
|
183 | + |
|
184 | + public function getId(): int { |
|
185 | + return $this->file->getId(); |
|
186 | + } |
|
187 | 187 | } |