Skip to content

Commit 1f290f5

Browse files
authored
Merge pull request #4396 from arogl/archive_mtime
Preserve mtimes from archives #4392
2 parents ed1202b + 6777b49 commit 1f290f5

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
@@ -1122,6 +1122,19 @@ def extract(self):
11221122
archive = handler_class(util.py3_path(self.toppath), mode='r')
11231123
try:
11241124
archive.extractall(extract_to)
1125+
1126+
# Adjust the files' mtimes to match the information from the
1127+
# archive. Inspired by: https://stackoverflow.com/q/9813243
1128+
for f in archive.infolist():
1129+
# The date_time will need to adjusted otherwise
1130+
# the item will have the current date_time of extraction.
1131+
# The (0, 0, -1) is added to date_time because the
1132+
# function time.mktime expects a 9-element tuple.
1133+
# The -1 indicates that the DST flag is unknown.
1134+
date_time = time.mktime(f.date_time + (0, 0, -1))
1135+
fullpath = os.path.join(extract_to, f.filename)
1136+
os.utime(fullpath, (date_time, date_time))
1137+
11251138
finally:
11261139
archive.close()
11271140
self.extracted = True

docs/changelog.rst

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ New features:
5252
* :ref:`import-options`: Add support for re-running the importer on paths in
5353
log files that were created with the ``-l`` (or ``--logfile``) argument.
5454
:bug:`4379` :bug:`4387`
55+
* Preserve mtimes from archives
56+
:bug:`4392`
5557
* Add :ref:`%sunique{} <sunique>` template to disambiguate between singletons.
5658
:bug:`4438`
5759
* Add a new ``import.ignored_alias_types`` config option to allow for

0 commit comments

Comments
 (0)