Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix format_name property and move it to ArchiveRead #127

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions libarchive/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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._pointer)


class ConsumedArchiveEntry(ArchiveEntry):

Expand Down
4 changes: 4 additions & 0 deletions libarchive/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_rwx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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')
Expand Down
Loading