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