Skip to content
Merged
Changes from 1 commit
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
Next Next commit
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 <[email protected]>
  • Loading branch information
susnux committed Aug 14, 2025
commit bb72eed4a2a558300111dd67750e14aa57e1e4ea
15 changes: 13 additions & 2 deletions lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -156,7 +157,7 @@ public function addFileFromStream($stream, string $internalName, int|float $size
$options = [];
if ($time) {
$options = [
'timestamp' => $time
'timestamp' => $this->fixTimestamp($time),
];
}

Expand All @@ -176,7 +177,7 @@ public function addFileFromStream($stream, string $internalName, int|float $size
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);
Expand All @@ -191,4 +192,14 @@ public function addEmptyDir(string $dirName, int $timestamp = 0): bool {
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;
}
}