diff --git a/apps/dashboard/lib/Service/BackgroundService.php b/apps/dashboard/lib/Service/BackgroundService.php index c98b92412cbb5..45b1f4f5dcf3a 100644 --- a/apps/dashboard/lib/Service/BackgroundService.php +++ b/apps/dashboard/lib/Service/BackgroundService.php @@ -38,6 +38,8 @@ use OCP\IConfig; use OCP\Lock\LockedException; use OCP\PreConditionNotMetException; +use Safe\Exceptions\FilesystemException; +use function Safe\rewind; class BackgroundService { // true when the background is bright and need dark icons @@ -144,6 +146,7 @@ public function setDefaultBackground(): void { * @throws LockedException * @throws PreConditionNotMetException * @throws NoUserException + * @throws FilesystemException */ public function setFileBackground($path): void { $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom'); @@ -151,10 +154,12 @@ public function setFileBackground($path): void { /** @var File $file */ $file = $userFolder->get($path); $image = new \OCP\Image(); - if ($image->loadFromFileHandle($file->fopen('r')) === false) { + $stream = $file->fopen('r'); + if ($image->loadFromFileHandle($stream) === false) { throw new InvalidArgumentException('Invalid image file'); } - $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r')); + rewind($stream); + $this->getAppDataFolder()->newFile('background.jpg', $stream); } public function setShippedBackground($fileName): void {