From 1acb6aa7c0514a38500798d951f76a452c8c446a Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 2 Mar 2026 11:38:39 -0500 Subject: [PATCH] perf(files_external/s3): skip download in truncating modes in fopen Pre-filling the temp file with remote content is only necessary for modes that do NOT truncate but allow both reading and writing (such as 'r+', 'a+', 'c+'). Truncating modes like 'w+' don't need the original file, and skipping the download is more efficient. Signed-off-by: Josh --- apps/files_external/lib/Lib/Storage/AmazonS3.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index fdcbf33627e17..4fdc9beba8256 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -414,17 +414,17 @@ public function fopen(string $path, string $mode) { } case 'w': case 'wb': + case 'w+': + case 'wb+': $tmpFile = Server::get(ITempManager::class)->getTemporaryFile(); - $handle = fopen($tmpFile, 'w'); + $handle = fopen($tmpFile, $mode); return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile): void { $this->writeBack($tmpFile, $path); }); case 'a': case 'ab': case 'r+': - case 'w+': - case 'wb+': case 'a+': case 'x': case 'x+':