Problem/Motivation
When uploading a file whose name already exists on S3 but the s3fs cache table has no matching records (stale cache), AjaxController::createFileKey() crashes on line 172 with:
ValueError: max(): Argument #1 ($value) must contain at least one element in max()
The call max(array_keys($results)) fails because $results is empty when the LIKE query on s3fs_file returns no matching URIs, but the file already exists on S3 (detected by doesObjectExistV2).
Steps to reproduce
- Upload a file via an s3fs_cors widget (e.g. a video file)
- Upload a file with the same name again
- If the s3fs cache table is stale (does not contain the first file's record), the rename logic enters the cache-stale branch on line 167 but crashes because
$results is empty
Proposed resolution
Guard the max() call on line 172 so it defaults to 0 when $results is empty:
$suffix = $results !== [] ? max(array_keys($results)) : 0;
Remaining tasks
Review and commit the merge request.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #4
heddnThanks for the contribution