Skip to content

Commit 0feca5f

Browse files
juliusknorrbackportbot[bot]
authored andcommitted
fix: Read from local file stream to avoid locking during preview generation
Signed-off-by: Julius Knorr <[email protected]>
1 parent 15550db commit 0feca5f

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

lib/Service/RemoteService.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ public function fetchTargetThumbnail(File $file, string $target): ?string {
5858
* @return resource|string
5959
*/
6060
public function convertFileTo(File $file, string $format) {
61-
$useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal();
62-
if ($useTempFile) {
63-
$fileName = $file->getStorage()->getLocalFile($file->getInternalPath());
64-
$stream = fopen($fileName, 'r');
65-
} else {
66-
$stream = $file->fopen('r');
67-
}
61+
$fileName = $file->getStorage()->getLocalFile($file->getInternalPath());
62+
$stream = fopen($fileName, 'rb');
6863

6964
if ($stream === false) {
7065
throw new Exception('Failed to open stream');
@@ -98,16 +93,11 @@ public function convertTo(string $filename, $stream, string $format) {
9893
}
9994

10095
private function getRequestOptionsForFile(File $file, ?string $target = null): array {
101-
$useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal();
102-
if ($useTempFile) {
103-
$localFile = $file->getStorage()->getLocalFile($file->getInternalPath());
104-
if (!is_string($localFile)) {
105-
throw new NotFoundException('Could not get local file');
106-
}
107-
$stream = fopen($localFile, 'rb');
108-
} else {
109-
$stream = $file->fopen('rb');
96+
$localFile = $file->getStorage()->getLocalFile($file->getInternalPath());
97+
if (!is_string($localFile)) {
98+
throw new NotFoundException('Could not get local file');
11099
}
100+
$stream = fopen($localFile, 'rb');
111101

112102
$options = RemoteOptionsService::getDefaultOptions(25);
113103
$options['multipart'] = [

0 commit comments

Comments
 (0)