From bb72eed4a2a558300111dd67750e14aa57e1e4ea Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 13 Aug 2025 10:27:55 +0200 Subject: [PATCH] fix(Streamer): use localtime for ZIP files ZIP does not use a proper timestamp but uses something called "DOS time". This is a weird old format with some limitations like accuracy of only 2 seconds, but also no timezone information. Also unline UNIX time it is not relative to some specific point in time with timezone information, but is always considered to be the local time. Meaning we need to convert it first to the users local time. Signed-off-by: Ferdinand Thiessen --- lib/private/Streamer.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index e579c42c0d7..ca03295b026 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -14,6 +14,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IDateTimeZone; use OCP\IRequest; use ownCloud\TarStreamer\TarStreamer; use Psr\Log\LoggerInterface; @@ -156,7 +157,7 @@ class Streamer { $options = []; if ($time) { $options = [ - 'timestamp' => $time + 'timestamp' => $this->fixTimestamp($time), ]; } @@ -176,7 +177,7 @@ class Streamer { public function addEmptyDir(string $dirName, int $timestamp = 0): bool { $options = null; if ($timestamp > 0) { - $options = ['timestamp' => $timestamp]; + $options = ['timestamp' => $this->fixTimestamp($timestamp)]; } return $this->streamerInstance->addEmptyDir($dirName, $options); @@ -191,4 +192,14 @@ class Streamer { public function finalize() { return $this->streamerInstance->finalize(); } + + private function fixTimestamp(int $timestamp): int { + if ($this->streamerInstance instanceof ZipStreamer) { + // Zip does not support any timezone information + // while tar is interpreted as Unix time the Zip time is interpreted as local time of the user... + $zone = \OCP\Server::get(IDateTimeZone::class)->getTimeZone($timestamp); + $timestamp += $zone->getOffset(new \DateTimeImmutable('@' . (string)$timestamp)); + } + return $timestamp; + } }