|
38 | 38 | use OCP\IConfig; |
39 | 39 | use OCP\Lock\LockedException; |
40 | 40 | use OCP\PreConditionNotMetException; |
| 41 | +use Safe\Exceptions\FilesystemException; |
| 42 | +use function Safe\rewind; |
41 | 43 |
|
42 | 44 | class BackgroundService { |
43 | 45 | public const THEMING_MODE_DARK = 'dark'; |
@@ -143,17 +145,20 @@ public function setDefaultBackground(): void { |
143 | 145 | * @throws LockedException |
144 | 146 | * @throws PreConditionNotMetException |
145 | 147 | * @throws NoUserException |
| 148 | + * @throws FilesystemException |
146 | 149 | */ |
147 | 150 | public function setFileBackground($path): void { |
148 | 151 | $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom'); |
149 | 152 | $userFolder = $this->rootFolder->getUserFolder($this->userId); |
150 | 153 | /** @var File $file */ |
151 | 154 | $file = $userFolder->get($path); |
152 | 155 | $image = new \OCP\Image(); |
153 | | - if ($image->loadFromFileHandle($file->fopen('r')) === false) { |
| 156 | + $stream = $file->fopen('r'); |
| 157 | + if ($image->loadFromFileHandle($stream) === false) { |
154 | 158 | throw new InvalidArgumentException('Invalid image file'); |
155 | 159 | } |
156 | | - $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r')); |
| 160 | + rewind($stream); |
| 161 | + $this->getAppDataFolder()->newFile('background.jpg', $stream); |
157 | 162 | } |
158 | 163 |
|
159 | 164 | public function setShippedBackground($fileName): void { |
|
0 commit comments