Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the same mtime as in the ownCloud's FS for files inside #37222

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions changelog/unreleased/37222
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Change: Keep the mtime of files and folders inside the tarball

Previously, when a folder or several files were downloaded, a tarball (.tar for
mac, .zip for windows and linux) was created. Such tarball had the mtime of the
files and folders inside with the time they were added into the tarball, not the
one shown in ownCloud.

This change makes the mtime of the files and folders inside the tarball to be
maintained as they're shown in the ownCloud's FS.

https://github.com/owncloud/core/pull/37222
28 changes: 20 additions & 8 deletions lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ public function sendHeaders($name) {
}

/**
* Stream directory recursively
* Stream directory recursively. The mtime of the files and folder will be kept.
* @param string $dir
* @param string $internalDir
*/
public function addDirRecursive($dir, $internalDir='') {
$dirname = \basename($dir);
$rootDir = $internalDir . $dirname;
if (!empty($rootDir)) {
$this->streamerInstance->addEmptyDir($rootDir);
$dirOpts = [
'timestamp' => \OC\Files\Filesystem::filemtime($dir),
];
$this->streamerInstance->addEmptyDir($rootDir, $dirOpts);
}
$internalDir .= $dirname . '/';
// prevent absolute dirs
Expand All @@ -75,8 +78,11 @@ public function addDirRecursive($dir, $internalDir='') {
$file = $dir . '/' . $filename;
if (\OC\Files\Filesystem::is_file($file)) {
$filesize = \OC\Files\Filesystem::filesize($file);
$fileOpts = [
'timestamp' => \OC\Files\Filesystem::filemtime($file),
];
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$this->addFileFromStream($fh, $internalDir . $filename, $filesize);
$this->addFileFromStream($fh, $internalDir . $filename, $filesize, $fileOpts);
\fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
$this->addDirRecursive($file, $internalDir);
Expand All @@ -90,24 +96,30 @@ public function addDirRecursive($dir, $internalDir='') {
* @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 array $opts the options to be used while adding the file. Options might
* depend on the specific implementation used. Common options are:
* - "timestamp" => (int) the timestamp used as mtime. Use null to set the current time
* @return bool $success
*/
public function addFileFromStream($stream, $internalName, $size) {
public function addFileFromStream($stream, $internalName, $size, $opts = []) {
if ($this->streamerInstance instanceof ZipStreamer) {
return $this->streamerInstance->addFileFromStream($stream, $internalName);
return $this->streamerInstance->addFileFromStream($stream, $internalName, $opts);
} else {
return $this->streamerInstance->addFileFromStream($stream, $internalName, $size);
return $this->streamerInstance->addFileFromStream($stream, $internalName, $size, $opts);
}
}

/**
* Add an empty directory entry to the archive.
*
* @param string $dirName Directory Path and name to be added to the archive.
* @param array $opts the options to be used while adding the empty folder. Options might
* depend on the specific implementation used. Common options are:
* - "timestamp" => (int) the timestamp used as mtime. Use null to set the current time
* @return bool $success
*/
public function addEmptyDir($dirName) {
return $this->streamerInstance->addEmptyDir($dirName);
public function addEmptyDir($dirName, $opts = []) {
return $this->streamerInstance->addEmptyDir($dirName, $opts);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/private/legacy/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ public static function get($dir, $files, $params = null) {
$file = $dir . '/' . $file;
if (\OC\Files\Filesystem::is_file($file)) {
$fileSize = \OC\Files\Filesystem::filesize($file);
$fileOpts = [
'timestamp' => \OC\Files\Filesystem::filemtime($file),
];
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$streamer->addFileFromStream($fh, \basename($file), $fileSize);
$streamer->addFileFromStream($fh, \basename($file), $fileSize, $fileOpts);
\fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
$streamer->addDirRecursive($file);
Expand Down