diff options
author | Joas Schilling <coding@schilljs.com> | 2016-11-28 14:56:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-28 14:56:18 +0100 |
commit | 6cd02a7f432032868cdec71d9a391c943b50b853 (patch) | |
tree | 7fff02d13bd10f8698c0c37f8d2ccff452750c5f /lib | |
parent | 3950ce9223927c66eb9f3f9f82475a19af617ed4 (diff) | |
parent | 6b8c45d05afbd7cd4e4e762ee0c71a39c0d80b34 (diff) | |
download | nextcloud-server-6cd02a7f432032868cdec71d9a391c943b50b853.tar.gz nextcloud-server-6cd02a7f432032868cdec71d9a391c943b50b853.zip |
Merge pull request #2367 from nextcloud/issue-2349-keep-filemtime-for-zip-downloads
Keep the filemtime for files when downloading them in a zip/tar
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Streamer.php | 17 | ||||
-rw-r--r-- | lib/private/legacy/files.php | 3 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index 75877ab166a..7b178fda652 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -76,8 +76,9 @@ class Streamer { $file = $dir . '/' . $filename; if(\OC\Files\Filesystem::is_file($file)) { $filesize = \OC\Files\Filesystem::filesize($file); + $fileTime = \OC\Files\Filesystem::filemtime($file); $fh = \OC\Files\Filesystem::fopen($file, 'r'); - $this->addFileFromStream($fh, $internalDir . $filename, $filesize); + $this->addFileFromStream($fh, $internalDir . $filename, $filesize, $fileTime); fclose($fh); }elseif(\OC\Files\Filesystem::is_dir($file)) { $this->addDirRecursive($file, $internalDir); @@ -91,13 +92,21 @@ class Streamer { * @param string $stream Stream to read data from * @param string $internalName Filepath and name to be used in the archive. * @param int $size Filesize + * @param int|bool $time File mtime as int, or false * @return bool $success */ - public function addFileFromStream($stream, $internalName, $size){ + public function addFileFromStream($stream, $internalName, $size, $time) { + $options = []; + if ($time) { + $options = [ + 'timestamp' => $time + ]; + } + if ($this->streamerInstance instanceof ZipStreamer) { - return $this->streamerInstance->addFileFromStream($stream, $internalName); + return $this->streamerInstance->addFileFromStream($stream, $internalName, $options); } else { - return $this->streamerInstance->addFileFromStream($stream, $internalName, $size); + return $this->streamerInstance->addFileFromStream($stream, $internalName, $size, $options); } } diff --git a/lib/private/legacy/files.php b/lib/private/legacy/files.php index 064fa9e1d7a..b6c6857a1bf 100644 --- a/lib/private/legacy/files.php +++ b/lib/private/legacy/files.php @@ -153,8 +153,9 @@ class OC_Files { $file = $dir . '/' . $file; if (\OC\Files\Filesystem::is_file($file)) { $fileSize = \OC\Files\Filesystem::filesize($file); + $fileTime = \OC\Files\Filesystem::filemtime($file); $fh = \OC\Files\Filesystem::fopen($file, 'r'); - $streamer->addFileFromStream($fh, basename($file), $fileSize); + $streamer->addFileFromStream($fh, basename($file), $fileSize, $fileTime); fclose($fh); } elseif (\OC\Files\Filesystem::is_dir($file)) { $streamer->addDirRecursive($file); |