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