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 <opensource@fthiessen.de>
pull/54402/head
Ferdinand Thiessen 5 months ago
parent d7f66eaee4
commit bb72eed4a2
  1. 15
      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;
}
}

Loading…
Cancel
Save