Skip to content

Commit

Permalink
No prefetch in "stream_open()"
Browse files Browse the repository at this point in the history
"$this->request_chunk(256 * 1024);" at the end of "stream_open()"
fetches a chunk of file contents. But when "stream_close()" is called
without calling "stream_read()", it tries to read status code from
"request_chunk()". Which lead to stream_close() to return false.

After this, regular files are displayed as folders. Previews are not
generated.

Instead of fetching chunk in "stream_open()", make the "stream_read()"
call both "request_chunk()" and "read_chunk()" it it.

Issue #25788

Signed-off-by: Rae Kim <rae.kim@raekim.me>
  • Loading branch information
Rae Kim committed Sep 16, 2023
1 parent f8ccaf8 commit 978be66
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions apps/files_external/lib/Lib/Storage/SFTPReadStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ public function stream_open($path, $mode, $options, &$opened_path) {
return false;
}

$this->request_chunk(256 * 1024);

return true;
}

Expand All @@ -126,12 +124,10 @@ public function stream_tell() {
}

public function stream_read($count) {
if (!$this->eof && strlen($this->buffer) < $count) {
while (strlen($this->buffer) < $count && !$this->eof) {
$this->request_chunk(256 * 1024);
$chunk = $this->read_chunk();
$this->buffer .= $chunk;
if (!$this->eof) {
$this->request_chunk(256 * 1024);
}
}

$data = substr($this->buffer, 0, $count);
Expand Down

0 comments on commit 978be66

Please sign in to comment.