From 16b98ce4d1b1992792ab8bf6b0edb2888bc33f72 Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 15 Apr 2024 18:59:05 +0200 Subject: [PATCH] fix downloads via WebDAV of backups stored in S3, caused by slightly wrong Content-Size header, due to encryption of backups --- api/src/WebDAV/Server/Filesystem.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/src/WebDAV/Server/Filesystem.php b/api/src/WebDAV/Server/Filesystem.php index 4cfd7f8594..de33e8b5a4 100644 --- a/api/src/WebDAV/Server/Filesystem.php +++ b/api/src/WebDAV/Server/Filesystem.php @@ -403,7 +403,7 @@ class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server // detect modification time // see rfc2518, section 13.7 // some clients seem to treat this as a reverse rule - // requiering a Last-Modified header if the getlastmodified header was set + // requiring a Last-Modified header if the getlastmodified header was set $options['mtime'] = filemtime($fspath); // detect resource size @@ -436,6 +436,16 @@ class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server // no need to check result here, it is handled by the base class $options['stream'] = fopen($fspath, "r"); + // hack to fix downloads from s3direct stream-wrapper reporting slightly wrong sizes in stat calls due to encryption + if (class_exists('EGroupware\Api\Vfs') && + ($url=EGroupware\Api\Vfs::resolve_url($options['path'])) && + str_starts_with($url, 'stylite.s3direct://')) + { + fseek($options['stream'], 0, SEEK_END); + $options['size'] = ftell($options['stream']); + fseek($options['stream'], 0); + } + return true; } @@ -939,4 +949,4 @@ class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server * c-basic-offset: 4 * indent-tabs-mode:nil * End: - */ + */ \ No newline at end of file