From 6c98ad609f012054a8b28505e64154ce046a1f60 Mon Sep 17 00:00:00 2001 From: Changaco Date: Sun, 3 Mar 2024 14:54:59 +0100 Subject: [PATCH 1/3] fix `AttributeError` in `ArchiveEntry.format_name` closes #126 --- libarchive/entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libarchive/entry.py b/libarchive/entry.py index 20f1adb..44c3b97 100644 --- a/libarchive/entry.py +++ b/libarchive/entry.py @@ -435,7 +435,7 @@ def rdevminor(self, value): @property def format_name(self): - return ffi.format_name(self._pointer) + return ffi.format_name(self._archive_p) class ConsumedArchiveEntry(ArchiveEntry): From 84cbf407c330c42139e204ca999b3328647c12fb Mon Sep 17 00:00:00 2001 From: Changaco Date: Sun, 3 Mar 2024 15:17:34 +0100 Subject: [PATCH 2/3] move `format_name` from `ArchiveEntry` to `ArchiveRead` --- libarchive/entry.py | 4 ---- libarchive/read.py | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libarchive/entry.py b/libarchive/entry.py index 44c3b97..70701ef 100644 --- a/libarchive/entry.py +++ b/libarchive/entry.py @@ -433,10 +433,6 @@ def rdevminor(self): def rdevminor(self, value): ffi.entry_set_rdevminor(self._entry_p, value) - @property - def format_name(self): - return ffi.format_name(self._archive_p) - class ConsumedArchiveEntry(ArchiveEntry): diff --git a/libarchive/read.py b/libarchive/read.py index fd18667..3451376 100644 --- a/libarchive/read.py +++ b/libarchive/read.py @@ -39,6 +39,10 @@ def filter_names(self): count = ffi.filter_count(self._pointer) return [ffi.filter_name(self._pointer, i) for i in range(count - 1)] + @property + def format_name(self): + return ffi.format_name(self._pointer) + @contextmanager def new_archive_read(format_name='all', filter_name='all', passphrase=None): From 4d72c7d61979feea8afbf56a978bf48ab75a4209 Mon Sep 17 00:00:00 2001 From: Changaco Date: Sun, 3 Mar 2024 15:19:58 +0100 Subject: [PATCH 3/3] test `format_name` and `filter_names` --- tests/test_rwx.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_rwx.py b/tests/test_rwx.py index 5daf201..77c16fc 100644 --- a/tests/test_rwx.py +++ b/tests/test_rwx.py @@ -26,6 +26,8 @@ def test_buffers(tmpdir): # Read the archive and check that the data is correct with libarchive.memory_reader(buf) as archive: check_archive(archive, tree) + assert archive.format_name == b'GNU tar format' + assert archive.filter_names == [b'xz'] # Extract the archive in tmpdir and check that the data is intact with in_dir(tmpdir.strpath): @@ -50,6 +52,8 @@ def test_fd(tmpdir): archive_file.seek(0) with libarchive.fd_reader(fd) as archive: check_archive(archive, tree) + assert archive.format_name == b'GNU tar format' + assert archive.filter_names == [b'bzip2'] # Extract the archive in tmpdir and check that the data is intact archive_file.seek(0) @@ -73,6 +77,8 @@ def test_files(tmpdir): # Read the archive and check that the data is correct with libarchive.file_reader(archive_path) as archive: check_archive(archive, tree) + assert archive.format_name == b'POSIX ustar format' + assert archive.filter_names == [b'gzip'] # Extract the archive in tmpdir and check that the data is intact with in_dir(tmpdir.strpath): @@ -95,6 +101,8 @@ def test_custom_writer_and_stream_reader(): # Read the archive and check that the data is correct with libarchive.stream_reader(stream, 'zip') as archive: check_archive(archive, tree) + assert archive.format_name == b'ZIP 2.0 (deflation)' + assert archive.filter_names == [] @patch('libarchive.ffi.write_fail')