diff options
author | Adrian Sampson <adrian@radbox.org> | 2023-04-01 16:07:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-01 16:07:34 -0700 |
commit | 1f290f532fd932ccfe7e71a882b0f173ca232d50 (patch) | |
tree | 89c2cc8eb3c784f830fb329ac68c2eb22c8e9431 | |
parent | ed1202bc94488e030e320181a76ba5dbe3a759e0 (diff) | |
parent | 6777b49bcff3f12013dc78ec0845483ff0c787f9 (diff) |
Merge pull request #4396 from arogl/archive_mtime
Preserve mtimes from archives #4392
-rw-r--r-- | beets/importer.py | 13 | ||||
-rw-r--r-- | docs/changelog.rst | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/beets/importer.py b/beets/importer.py index feebadc09..96d1f17df 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -1122,6 +1122,19 @@ class ArchiveImportTask(SentinelImportTask): archive = handler_class(util.py3_path(self.toppath), mode='r') try: archive.extractall(extract_to) + + # Adjust the files' mtimes to match the information from the + # archive. Inspired by: https://stackoverflow.com/q/9813243 + for f in archive.infolist(): + # The date_time will need to adjusted otherwise + # the item will have the current date_time of extraction. + # The (0, 0, -1) is added to date_time because the + # function time.mktime expects a 9-element tuple. + # The -1 indicates that the DST flag is unknown. + date_time = time.mktime(f.date_time + (0, 0, -1)) + fullpath = os.path.join(extract_to, f.filename) + os.utime(fullpath, (date_time, date_time)) + finally: archive.close() self.extracted = True diff --git a/docs/changelog.rst b/docs/changelog.rst index 435c85709..aaeb32e41 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -52,6 +52,8 @@ New features: * :ref:`import-options`: Add support for re-running the importer on paths in log files that were created with the ``-l`` (or ``--logfile``) argument. :bug:`4379` :bug:`4387` +* Preserve mtimes from archives + :bug:`4392` * Add :ref:`%sunique{} <sunique>` template to disambiguate between singletons. :bug:`4438` * Add a new ``import.ignored_alias_types`` config option to allow for |