importer: fix tar and 7z archive import#6696
Open
bcotton wants to merge 1 commit into
Open
Conversation
Both `tarfile.TarFile` and `py7zr.SevenZipFile` lack an `infolist()` method, which `ArchiveImportTask.extract` relies on to iterate members and restore mtimes. `TarFile` lost it when `ZipFileCompat` was removed in Python 3; `SevenZipFile` exposes `list()` instead. Both surfaces raised `'... object has no attribute 'infolist'` during import. Add thin module-level wrappers — `TarArchive` (subclass) and `SevenZipArchive` (composition, since `py7zr` is optional) — that adapt their respective backends to the ZipFile-compatible interface. Members are exposed via tiny adapter classes carrying only the two attributes the extract loop needs: `filename` and `date_time`. Also fix a latent test bug: `ImportTarTest.create_archive` and `Import7zTest`'s inheritance were dead code because the parent's `test_import_zip` called the module-level `create_archive` helper (which only knows how to make zips). Route through `self.create_archive` so the tar and 7z tests actually exercise their archive types.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6696 +/- ##
==========================================
+ Coverage 72.57% 72.60% +0.03%
==========================================
Files 162 162
Lines 20810 20831 +21
Branches 3292 3292
==========================================
+ Hits 15103 15125 +22
Misses 4982 4982
+ Partials 725 724 -1
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorry about the delay.
ArchiveImportTask.extractcallsarchive.infolist(), but neithertarfile.TarFile(lostZipFileCompatin Python 3) norpy7zr.SevenZipFile(exposeslist()instead) provides it. Both surfaces produced'… object has no attribute 'infolist'and aborted the import.TarArchive(subclass oftarfile.TarFile) andSevenZipArchive(composition overpy7zr.SevenZipFile, sincepy7zris optional) — that expose aZipFile-compatibleinfolist(). Tiny_TarMemberInfo/_SevenZipMemberInfoadapters carry only the two attributes the extract loop reads:filenameanddate_time.ImportTarTest.create_archiveandImport7zTest's inheritance were dead code. The parenttest_import_zipcalled the module-levelcreate_archive(self)helper, which only knows how to build zips, so both tar and 7z tests were silently exercising the zip path. Routing throughself.create_archive()makes them real regression tests for this bug.This supersedes #5666; design follows @wisp3rwind's review feedback there (module-level wrappers, minimal adapters, shared test infrastructure via
self.create_archive).Test plan
pytest test/test_importer.py::ImportZipTest test/test_importer.py::ImportTarTest test/test_importer.py::Import7zTest— all passbeets/importer/tasks.pyto master while keeping test changes reproduces the original'TarFile' object has no attribute 'infolist'and'SevenZipFile' object has no attribute 'infolist'errors (confirming the tests are real regression tests)pytest test/test_importer.py— full module: 127 passed, 5 skipped (env-dependent: reflink, unrar, unimplemented)beet importon a real.tararchive