Skip to content

Commit 14cd430

Browse files
committed
Preserve mtimes from archives beetbox#4392
1 parent 472c3ab commit 14cd430

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

beets/importer.py

+13
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,19 @@ def extract(self):
10901090
archive = handler_class(util.py3_path(self.toppath), mode='r')
10911091
try:
10921092
archive.extractall(extract_to)
1093+
1094+
# From here:
1095+
# https://stackoverflow.com/questions/9813243/extract-files-from-zip-file-and-retain-mod-date
1096+
# fixing #4392
1097+
1098+
for f in archive.infolist():
1099+
# path to this extracted f-item
1100+
fullpath = os.path.join(extract_to, f.filename)
1101+
# still need to adjust the dt o/w item will have the current dt
1102+
date_time = time.mktime(f.date_time + (0, 0, -1))
1103+
# update date_time
1104+
os.utime(fullpath, (date_time, date_time))
1105+
10931106
finally:
10941107
archive.close()
10951108
self.extracted = True

docs/changelog.rst

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ New features:
3232
* :ref:`import-options`: Add support for re-running the importer on paths in
3333
log files that were created with the ``-l`` (or ``--logfile``) argument.
3434
:bug:`4379` :bug:`4387`
35+
* Preserve mtimes from archives
36+
:bug:`4392`
3537

3638
Bug fixes:
3739

0 commit comments

Comments
 (0)