[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] File Galleries: Preserve original file metadata in zip downloads

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6983f78d88aa0_3b18461025d7@gitlab-sidekiq-low-urgency-cpu-bound-v2-7b76c8c4b-gjmt7.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
2ad8382f by Moïse Nturubika at 2026-02-05T01:42:43+00:00
[FIX] File Galleries: Preserve original file metadata in zip downloads
---
* [FIX] Use more precise error message

* [FIX] FileGalLib: Make zip download error messages translatable and descriptive

* [FIX] Preserve original file metadata in zip downloads

See merge request tikiwiki/tiki!9292

- - - - -


1 changed file:

- lib/Filegals/FileGalLib.php


Changes:

=====================================
lib/Filegals/FileGalLib.php
=====================================
@@ -1282,8 +1282,7 @@ class FileGalLib extends TikiLib
     {
         global $tiki_p_admin_file_galleries, $prefs, $user;
         $userlib = TikiLib::lib('user');
-
-        $list = [];
+        $tempFiles = [];
         $temp = '/' . md5(random_bytes(10)) . '/';
         if (! mkdir(sys_get_temp_dir() . $temp)) {
             $temp = sys_get_temp_dir() . $temp;
@@ -1336,15 +1335,19 @@ class FileGalLib extends TikiLib
                 $filenames[$pathKey][] = $filename;
                 $tmp = $destDir . $filename;
                 if (! copy($file->getWrapper()->getReadableFile(), $tmp)) {
-                    $error = "Can not copy to $tmp";
+                    $error = tr('Can not copy to %0', $tmp);
                     return false;
                 }
-                $list[] = $tmp;
+                $tempFiles[] = [
+                    'path' => $tmp,
+                    'filename' => $filename,
+                    'lastModif' => $file->lastModif,
+                ];
                 $info = $file->getParams();
             }
         }
-        if (empty($list)) {
-            $error = "No permission";
+        if (empty($tempFiles)) {
+            $error = tra('You do not have permission to download any of the selected files.');
             return null;
         }
         $info['filename'] = "$zipName.zip";
@@ -1354,7 +1357,16 @@ class FileGalLib extends TikiLib
             $error = $archive->errorInfo(true);
             return false;
         }
-        if (! ($v_list = $archive->create($list, PCLZIP_OPT_REMOVE_PATH, $temp))) {
+        // Use file descriptors with PCLZIP_ATT_FILE_MTIME to preserve original file timestamps
+        $list = [];
+        foreach ($tempFiles as $fileData) {
+            $list[] = [
+                PCLZIP_ATT_FILE_NAME => $fileData['path'],
+                PCLZIP_ATT_FILE_NEW_FULL_NAME => $fileData['filename'],
+                PCLZIP_ATT_FILE_MTIME => $fileData['lastModif'],
+            ];
+        }
+        if (! ($v_list = $archive->create($list))) {
             $error = $archive->errorInfo(true);
             return false;
         }
@@ -1362,8 +1374,9 @@ class FileGalLib extends TikiLib
         $info['path'] = '';
         $info['filetype'] = 'application/x-zip-compressed';
         $info['filesize'] = strlen($info['data']);
-
-        // Clean up temp directory using Symfony Filesystem
+        foreach ($tempFiles as $fileData) {
+            unlink($fileData['path']);
+        }
         unlink($zip);
         $fs = new Filesystem();
         $fs->remove($temp);



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2ad8382f78e80d7c98511422befdabc12bdd5cb8

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2ad8382f78e80d7c98511422befdabc12bdd5cb8
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.