0

I have Python libarchive 0.4.3 installed. I'd like to get the mtime of a 7z file as stored inside the 7z file. This is different than the mtime of the file stored locally on the disk. Let's say it is the underlying source C tarball lzma1604.7z.

The following program will list all of the files and the mtime of that. But I don't see the time for the entire 7z "tarball" as given in the 7z file.

from libarchive.public import memory_reader
with open('lzma1604.7z', 'rb') as f:
    buffer = f.read()

    with memory_reader(buffer) as archive:
        for entry in archive:
            print(entry.pathname, entry.mtime)

The above program prints:

('Asm/arm/7zCrcOpt.asm', datetime.datetime(2009, 10, 8, 5, 12))
('Asm/x86/7zAsm.asm', datetime.datetime(2012, 12, 30, 3, 41, 54))
...
('bin/7zSD.sfx', datetime.datetime(2016, 10, 4, 11, 12, 31))
('bin/lzma.exe', datetime.datetime(2016, 10, 4, 11, 12, 30))
('bin/x64/7zr.exe', datetime.datetime(2016, 10, 4, 10, 58, 29))

But if I run 7z l lzma1604.7z that gives at the end:

2016-10-04 10:12:31 ....A       113152               bin/7zSD.sfx
2016-10-04 10:12:30 ....A        97280               bin/lzma.exe
2016-10-04 09:58:29 ....A       742400               bin/x64/7zr.exe
------------------- ----- ------------ ------------  ------------------------
2016-10-04 10:27:55            4534441       960121  620 files

So how do I get in Python via libarchive the information, specifically, the mtime of the overall archive?

rocky
  • 7,226
  • 3
  • 33
  • 74
  • I can’t found any useful reference in the source code here http://www.7-zip.org/sdk.html. Maybe this time is calculated?… – Laurent LAPORTE Nov 08 '16 at 13:43
  • For other fields, yes. But for the time? https://github.com/yurket/lzma-sdk-zlibLike/blob/master/7zMain.c#L391-L392 suggests it is in the file, but possibly not always. I have a feeling that it is just not in the bindings. – rocky Nov 08 '16 at 13:54
  • 1
    The **Header** has the following info: *ArchiveProperties*, *StreamsInfo*, *StreamsInfo*, *FilesInfo*. Which are all optional. The **FilesInfo** can contain *cTime*, *aTime* and *mTime*. But I don't know how to get them from Python. – Laurent LAPORTE Nov 08 '16 at 14:00

0 Answers0