[Done] UncompressPackFile() should preserve modification times

Post bugreports for the Windows version here
Little John
Addict
Addict
Posts: 4798
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

[Done] UncompressPackFile() should preserve modification times

Post by Little John »

When I recently used PB's built-in packer lib for the first time, I was flabbergasted to see that after unpacking files from an archive, all file modification times are set to the current time.

Code: Select all

; Code tested with:
; PB 6.30 beta 2 (x64) on Windows 11

EnableExplicit

UseZipPacker()
#Mask$ = "%yyyy-%mm-%dd"

Global g_TempPath$ = GetTemporaryDirectory() + "PureBasicTemp/"


Procedure.i Unpack (archive$)
   Protected.i ifn, count=0, ret=0
   Protected pkCreated$, pkAccessed$, pkModified$
   Protected created$, accessed$, modified$
   
   ifn = OpenPack(#PB_Any, archive$)
   If ifn = 0
      ProcedureReturn 1  ; error
   EndIf
   
   If FileSize(g_TempPath$) <> -2 And CreateDirectory(g_TempPath$) = 0
      ClosePack(ifn)
      ProcedureReturn 2  ; error
   EndIf
   
   If ExaminePack(ifn)
      Debug "Files in archive '" + archive$ + "'"
      Debug ""
      Debug Space(46) + "PACKED" + Space(19) + "|" + Space(15) + "UNPACKED"
      Debug LSet("Name", 30) + "   Created      Accessed     Modified    |  Created      Accessed     Modified"
      Debug "-----------------------------    ----------   ----------   ----------  |  ----------   ----------   ----------"
      
      While NextPackEntry(ifn)
         If PackEntryType(ifn) = #PB_Packer_File
            count + 1
            If UncompressPackFile(ifn, g_TempPath$ + PackEntryName(ifn)) = -1
               Debug "Error: unsuccessful unpacking of file: " + PackEntryName(ifn)
               ret = 3  ; error
            Else
               pkCreated$  = RSet(FormatDate(#Mask$, PackEntryDate(ifn, #PB_Date_Created)),  13)
               pkAccessed$ = RSet(FormatDate(#Mask$, PackEntryDate(ifn, #PB_Date_Accessed)), 13)
               pkModified$ = RSet(FormatDate(#Mask$, PackEntryDate(ifn, #PB_Date_Modified)), 13)
               
               created$  = RSet(FormatDate(#Mask$, GetFileDate(g_TempPath$ + PackEntryName(ifn), #PB_Date_Created)),  12)
               accessed$ = RSet(FormatDate(#Mask$, GetFileDate(g_TempPath$ + PackEntryName(ifn), #PB_Date_Accessed)), 13)
               modified$ = RSet(FormatDate(#Mask$, GetFileDate(g_TempPath$ + PackEntryName(ifn), #PB_Date_Modified)), 13)
               
               Debug LSet(PackEntryName(ifn), 30) +
                     pkCreated$ + pkAccessed$ + pkModified$ + "  |" +
                     created$ + accessed$ + modified$
            EndIf
            
            If count = 10     ; TODO: Set this to 0 to show all entries.
               Debug "[...]"
               Break
            EndIf
         EndIf
      Wend
      Debug ""
   EndIf
   ClosePack(ifn)
   
   ProcedureReturn ret
EndProcedure


Debug Unpack("C:\Program Files\PureBasic\Themes\SilkTheme.zip")
; Program version in this directory:
; PB 6.30 beta 2 (x64) on Windows 11
 
Output:

Code: Select all

Files in archive 'C:\Program Files\PureBasic\Themes\SilkTheme.zip'

                                              PACKED                   |               UNPACKED
Name                             Created      Accessed     Modified    |  Created      Accessed     Modified
-----------------------------    ----------   ----------   ----------  |  ----------   ----------   ----------
accept.png                                    2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
add.png                                       2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_add.png                           2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_form.png                          2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_form_add.png                      2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_home.png                          2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_tile_vertical.png                 2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_view_columns.png                  2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_view_gallery.png                  2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
application_view_tile.png                     2025-09-12   2020-09-28  |  2025-09-15   2025-09-16   2025-09-16
[...]

0
 
This should not happen IMHO. Other professional programs that unpack archives on Windows (e.g. Total Commander) preserve the modification dates of packed files after unpacking them. Also PureBasic's CopyFile() and RenameFile() don't touch the modification dates of files. So for consistency and according to the principle of least surprise, UncompressPackFile() also shouldn't touch the modification date of the files.

PS: I know that we can use something like

Code: Select all

SetFileDate(g_TempPath$ + PackEntryName(ifn), #PB_Date_Modified, PackEntryDate(ifn))
for each file after unpacking. But I would appreciate it if PureBasic would handle that itself automatically.
User avatar
jacdelad
Addict
Addict
Posts: 2019
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: UncompressPackFile() should preserve modification times

Post by jacdelad »

How does this fit into the bug section? This is a request.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Fred
Administrator
Administrator
Posts: 18301
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: UncompressPackFile() should preserve modification times

Post by Fred »

I moved it here, it should be the default behaviour
Fred
Administrator
Administrator
Posts: 18301
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] UncompressPackFile() should preserve modification times

Post by Fred »

Fixed.
Post Reply