Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lazy open first source stream in assemblystream
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Oct 22, 2018
commit 2f518b6ac880cff556e3e52a84a4aa048eeaecbe
11 changes: 6 additions & 5 deletions apps/dav/lib/Upload/AssemblyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public function stream_open($path, $mode, $options, &$opened_path) {
return strnatcmp($a->getName(), $b->getName());
});
$this->nodes = array_values($nodes);
if (count($this->nodes) > 0) {
$this->currentStream = $this->getStream($this->nodes[0]);
}
$this->size = array_reduce($this->nodes, function ($size, IFile $file) {
return $size + $file->getSize();
}, 0);
Expand Down Expand Up @@ -107,7 +104,11 @@ public function stream_tell() {
*/
public function stream_read($count) {
if (is_null($this->currentStream)) {
return '';
if ($this->currentNode < count($this->nodes)) {
$this->currentStream = $this->getStream($this->nodes[$this->currentNode]);
} else {
return '';
}
}

do {
Expand Down Expand Up @@ -191,7 +192,7 @@ public function stream_flush() {
* @return bool
*/
public function stream_eof() {
return $this->pos >= $this->size || $this->currentStream === null;
return $this->pos >= $this->size || ($this->currentNode >= count($this->nodes) && $this->currentNode === null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this to me in words, because the code and variables make very little sense. The part before the || makes sense: if the position is bigger than the size it reached the end of the file. But the second part can never become true - is this really correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the second part should never be true, but in cases where the chunking fails the number of bytes read can become lower than expected which would lead to an infinite loop with only the first clause.

This patch is to fix that specific issue, but I figured it's better to leave the extra check there in case a similar issue occurs in the future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoudl being the keyword 😉

}

/**
Expand Down