Skip to content
Open
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
8 changes: 7 additions & 1 deletion apps/files_external/lib/Lib/Storage/FtpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ public function mlsd(string $path) {

// rawlist parsing logic is based on the ftp implementation from https://github.com/thephpleague/flysystem
private function parseRawList(array $rawList, string $directory): array {
$filtered = array_values(array_filter($rawList, static function (string $item): bool {
$item = trim($item);
// BSD ftpd (and some Unix servers) prepend listings with a "total N" header
return $item !== '' && !preg_match('/^total\b/i', $item);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return $item !== '' && !preg_match('/^total\b/i', $item);
return !str_starts_with($item, 'total ');

This is a lot cheaper.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, good call. Though the $item !== '' check still needed too since array_filter() being used with callback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand what you mean. Empty lines or lines with only whitespace weren't filtered out before, so why should they now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I meant that str_starts_with() only replaces the regex part of the condition. If we still intend to exclude empty/whitespace-only lines as described in the PR, $item !== '' remains necessary because array_filter() has a callback and therefore won't filter out empty values automatically. Without that check, str_starts_with() returns false for an empty haystack, so the negated condition returns true; the empty line then reaches the parser and causes the same "not enough parts" exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure, but I don't see any explanation why filtering out empty lines is necessary.

}));

return array_map(function ($item) use ($directory) {
return $this->parseRawListItem($item, $directory);
}, $rawList);
}, $filtered);
}

private function parseRawListItem(string $item, string $directory): array {
Expand Down
Loading