Browse Source

Merge pull request #17 from Vadiml1024/extended

Add support for password protected archives
test_fixup
Clifton Barnes 2 years ago
committed by GitHub
parent
commit
0b2eefb947
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 4857 additions and 2056 deletions
  1. +1
    -0
      Makefile
  2. +7
    -7
      libarchive/Makefile
  3. +76
    -16
      libarchive/__init__.py
  4. +183
    -17
      libarchive/_libarchive.i
  5. +438
    -326
      libarchive/_libarchive.py
  6. +3428
    -1456
      libarchive/_libarchive_wrap.c
  7. +361
    -98
      libarchive/archive.h
  8. +146
    -40
      libarchive/archive_entry.h
  9. +18
    -17
      libarchive/tar.py
  10. +32
    -18
      libarchive/zip.py
  11. +55
    -47
      setup.py
  12. +112
    -14
      tests.py

+ 1
- 0
Makefile View File

@@ -11,6 +11,7 @@ verify:
install:
python setup.py install


publish:
python setup.py register
python setup.py sdist upload


+ 7
- 7
libarchive/Makefile View File

@@ -1,19 +1,19 @@
CFLAGS = -g
INCLUDE = -I/usr/include -I.
LIBS = -larchive
INCLUDE = -I/usr/local/include -I/usr/include -I.
LIBS = -L /usr/local/lib -larchive

PYVER ?= 2.7
PYVER ?= 3.9

all: __libarchive.so

_libarchive_wrap.c: _libarchive.i
swig -python -shadow _libarchive.i
swig -python -Wall -shadow _libarchive.i

_libarchive_wrap.o: _libarchive_wrap.c
${CC} -c ${CFLAGS} -fPIC ${INCLUDE} $$(python${PYVER}-config --cflags) _libarchive_wrap.c
${CC} -c ${CFLAGS} -fPIC $$(python${PYVER}-config --cflags) _libarchive_wrap.c

__libarchive.so: _libarchive_wrap.o
${CC} _libarchive_wrap.o -shared $$(python${PYVER}-config --ldflags) -o __libarchive.so ${LIBS}
${CC} _libarchive_wrap.o -shared $$(python${PYVER}-config --ldflags) -Wl,-soname=__libarchive.so -o __libarchive.so ${LIBS}

clean:
rm -f *.o *.so *.pyc
rm -f *.o *.so *.pyc

+ 76
- 16
libarchive/__init__.py View File

@@ -28,11 +28,10 @@ import stat
import sys
import time
import warnings

from libarchive import _libarchive
from io import StringIO

PY3 = sys.version_info[0] == 3
PY3 = sys.version_info[0] >= 3

# Suggested block size for libarchive. Libarchive may adjust it.
BLOCK_SIZE = 10240
@@ -88,8 +87,13 @@ FILTER_EXTENSIONS = {
class EOF(Exception):
'''Raised by ArchiveInfo.from_archive() when unable to read the next
archive header.'''

pass

def version():
'''Returns the version of the libarchive library.'''
return _libarchive.archive_version_string().split()[1]


def get_error(archive):
'''Retrieves the last error description for the given archive instance.'''
@@ -106,7 +110,7 @@ def call_and_check(func, archive, *args):
elif ret == _libarchive.ARCHIVE_EOF:
raise EOF()
else:
raise Exception('Fatal error executing function, message is: %s.' % get_error(archive))
raise Exception('Problem executing function, message is: %s.' % get_error(archive))


def get_func(name, items, index):
@@ -142,7 +146,7 @@ def is_archive_name(filename, formats=None):
return format


def is_archive(f, formats=(None, ), filters=(None, )):
def is_archive(f, formats=(None,), filters=(None,)):
'''Check to see if the given file is actually an archive. The format parameter
can be used to specify which archive format is acceptable. If ommitted, all supported
archive formats will be checked. It opens the file using libarchive. If no error is
@@ -155,8 +159,10 @@ def is_archive(f, formats=(None, ), filters=(None, )):

This function will return True if the file can be opened as an archive using the given
format(s)/filter(s).'''
need_close = False
if isinstance(f, str):
f = open(f, 'r')
f = open(f, 'rb')
need_close = True
a = _libarchive.archive_read_new()
for format in formats:
format = get_func(format, FORMATS, 0)
@@ -177,11 +183,13 @@ def is_archive(f, formats=(None, ), filters=(None, )):
finally:
_libarchive.archive_read_close(a)
_libarchive.archive_read_free(a)
f.close()
if need_close:
f.close()


class EntryReadStream(object):
'''A file-like object for reading an entry from the archive.'''

def __init__(self, archive, size):
self.archive = archive
self.closed = False
@@ -241,6 +249,7 @@ class EntryWriteStream(object):
If the size is known ahead of time and provided, then the file contents
are not buffered but flushed directly to the archive. If size is omitted,
then the file contents are buffered and flushed in the close() method.'''

def __init__(self, archive, pathname, size=None):
self.archive = archive
self.entry = Entry(pathname=pathname, mtime=time.time(), mode=stat.S_IFREG)
@@ -274,7 +283,7 @@ class EntryWriteStream(object):
if self.buffer:
self.buffer.write(data)
else:
_libarchive.archive_write_data_from_str(self.archive._a, data.encode('utf-8'))
_libarchive.archive_write_data_from_str(self.archive._a, data.encode(ENCODING))
self.bytes += len(data)

def close(self):
@@ -283,7 +292,7 @@ class EntryWriteStream(object):
if self.buffer:
self.entry.size = self.buffer.tell()
self.entry.to_archive(self.archive)
_libarchive.archive_write_data_from_str(self.archive._a, self.buffer.getvalue().encode('utf-8'))
_libarchive.archive_write_data_from_str(self.archive._a, self.buffer.getvalue().encode(ENCODING))
_libarchive.archive_write_finish_entry(self.archive._a)

# Call archive.close() with _defer True to let it know we have been
@@ -295,7 +304,9 @@ class EntryWriteStream(object):

class Entry(object):
'''An entry within an archive. Represents the header data and it's location within the archive.'''

def __init__(self, pathname=None, size=None, mtime=None, mode=None, hpos=None, encoding=ENCODING):

self.pathname = pathname
self.size = size
self.mtime = mtime
@@ -303,6 +314,8 @@ class Entry(object):
self.hpos = hpos
self.encoding = encoding

self.symlink = ""

@property
def header_position(self):
return self.hpos
@@ -328,6 +341,11 @@ class Entry(object):
mode=mode,
hpos=archive.header_position,
)

if entry.issym():
symLinkPath = _libarchive.archive_entry_symlink(e)
entry.symlink = symLinkPath

finally:
_libarchive.archive_entry_free(e)
return entry
@@ -356,6 +374,8 @@ class Entry(object):
entry.size = getattr(f, 'size', 0)
entry.mtime = getattr(f, 'mtime', time.time())
entry.mode = stat.S_IFREG

return entry

def to_archive(self, archive):
@@ -370,8 +390,12 @@ class Entry(object):
_libarchive.archive_entry_set_perm(e, stat.S_IMODE(self.mode))
_libarchive.archive_entry_set_size(e, self.size)
_libarchive.archive_entry_set_mtime(e, self.mtime, 0)

if stat.S_ISLNK(self.mode):
_libarchive.archive_entry_set_symlink(e, self.symlink)

call_and_check(_libarchive.archive_write_header, archive._a, archive._a, e)
#self.hpos = archive.header_position
finally:
_libarchive.archive_entry_free(e)

@@ -397,11 +421,23 @@ class Entry(object):
class Archive(object):
'''A low-level archive reader which provides forward-only iteration. Consider
this a light-weight pythonic libarchive wrapper.'''
def __init__(self, f, mode='r', format=None, filter=None, entry_class=Entry, encoding=ENCODING, blocksize=BLOCK_SIZE):

def __init__(
self,
f,
mode='r',
format=None,
filter=None,
entry_class=Entry,
encoding=ENCODING,
blocksize=BLOCK_SIZE,
password=None,
):
assert mode in ('r', 'w', 'wb', 'a'), 'Mode should be "r", "w", "wb", or "a".'
self._stream = None
self.encoding = encoding
self.blocksize = blocksize
self.password = password
if isinstance(f, str):
self.filename = f
f = open(f, mode)
@@ -462,6 +498,9 @@ class Archive(object):
def __del__(self):
self.close()

def set_initial_options(self):
pass

def init(self):
if self.mode == 'r':
self._a = _libarchive.archive_read_new()
@@ -469,9 +508,18 @@ class Archive(object):
self._a = _libarchive.archive_write_new()
self.format_func(self._a)
self.filter_func(self._a)
self.set_initial_options()
if self.mode == 'r':
if self.password:
if isinstance(self.password, list):
for pwd in self.password:
self.add_passphrase(pwd)
else:
self.add_passphrase(self.password)
call_and_check(_libarchive.archive_read_open_fd, self._a, self._a, self.f.fileno(), self.blocksize)
else:
if self.password:
self.set_passphrase(self.password)
call_and_check(_libarchive.archive_write_open_fd, self._a, self._a, self.f.fileno())

def denit(self):
@@ -509,9 +557,11 @@ class Archive(object):
if getattr(self.f, 'closed', False):
return
# Flush it if not read-only...
if self.f.mode != 'r' and self.f.mode != 'rb':
self.f.flush()
os.fsync(self.f.fileno())
if hasattr(self.f, "mode") and self.f.mode != 'r' and self.f.mode != 'rb':
if hasattr(self.f, "flush"):
self.f.flush()
if hasattr(self.f, "fileno"):
os.fsync(self.f.fileno())
# and then close it, if we opened it...
if getattr(self, '_close', None):
self.f.close()
@@ -533,7 +583,7 @@ class Archive(object):
'''Write current archive entry contents to file. f can be a file-like object or
a path.'''
if isinstance(f, str):
basedir = os.path.basename(f)
basedir = os.path.dirname(f)
if not os.path.exists(basedir):
os.makedirs(basedir)
f = open(f, 'w')
@@ -547,7 +597,8 @@ class Archive(object):
def write(self, member, data=None):
'''Writes a string buffer to the archive as the given entry.'''
if isinstance(member, str):
member = self.entry_class(pathname=member, encoding=self.encoding)
member = self.entry_class(pathname=member, encoding=self.encoding,
mtime=time.time(), mode=stat.S_IFREG)
if data:
member.size = len(data)
member.to_archive(self)
@@ -557,7 +608,7 @@ class Archive(object):
if isinstance(data, bytes):
result = _libarchive.archive_write_data_from_str(self._a, data)
else:
result = _libarchive.archive_write_data_from_str(self._a, data.encode('utf8'))
result = _libarchive.archive_write_data_from_str(self._a, data.encode(self.encoding))
else:
result = _libarchive.archive_write_data_from_str(self._a, data)
_libarchive.archive_write_finish_entry(self._a)
@@ -594,6 +645,14 @@ class Archive(object):
s.write(entry.pathname)
s.flush()

def add_passphrase(self, password):
'''Adds a password to the archive.'''
_libarchive.archive_read_add_passphrase(self._a, password)

def set_passphrase(self, password):
'''Sets a password for the archive.'''
_libarchive.archive_write_set_passphrase(self._a, password)


class SeekableArchive(Archive):
'''A class that provides random-access to archive entries. It does this by using one
@@ -601,6 +660,7 @@ class SeekableArchive(Archive):
occur when reading archive entries in the order in which they appear in the archive.
Reading out of order will cause the archive to be closed and opened each time a
reverse seek is needed.'''

def __init__(self, f, **kwargs):
self._stream = None
# Convert file to open file. We need this to reopen the archive.


+ 183
- 17
libarchive/_libarchive.i View File

@@ -72,8 +72,6 @@

typedef unsigned short mode_t;

# Everything below is from the archive.h and archive_entry.h files.
# I excluded functions declarations that are not needed.

/* CONFIGURATION */

@@ -155,8 +153,8 @@ extern int archive_read_free(struct archive *);
extern int archive_read_open_filename(struct archive *,
const char *_filename, size_t _block_size);
extern int archive_read_open_memory(struct archive *,
void * buff, size_t size);
extern int archive_read_open_memory2(struct archive *a, void *buff,
const void * buff, size_t size);
extern int archive_read_open_memory2(struct archive *a, void const *buff,
size_t size, size_t read_size);
extern int archive_read_open_fd(struct archive *, int _fd,
size_t _block_size);
@@ -171,39 +169,107 @@ extern int archive_read_next_header2(struct archive *,
extern const struct stat *archive_entry_stat(struct archive_entry *);
extern __LA_INT64_T archive_read_header_position(struct archive *);

/*
* Set read options.
*/
/* Apply option to the format only. */
extern int archive_read_set_format_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option to the filter only. */
extern int archive_read_set_filter_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option to both the format and the filter. */
extern int archive_read_set_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option string to both the format and the filter. */
extern int archive_read_set_options(struct archive *_a,
const char *opts);

/*
* Add a decryption passphrase.
*/
extern int archive_read_add_passphrase(struct archive *, const char *);
/* data */
extern int archive_read_data_skip(struct archive *);
extern int archive_read_data_into_fd(struct archive *, int fd);

/* FILTERS */
#if ARCHIVE_VERSION_NUMBER < 4000000
extern int archive_read_support_compression_all(struct archive *);
extern int archive_read_support_compression_bzip2(struct archive *);
extern int archive_read_support_compression_compress(struct archive *);
extern int archive_read_support_compression_gzip(struct archive *);
extern int archive_read_support_compression_lzip(struct archive *);
extern int archive_read_support_compression_lzma(struct archive *);
extern int archive_read_support_compression_none(struct archive *);
extern int archive_read_support_compression_program(struct archive *, const char *command);
extern int archive_read_support_compression_program_signature
(struct archive *, const char *,
const void * /* match */, size_t);

extern int archive_read_support_compression_rpm(struct archive *);
extern int archive_read_support_compression_uu(struct archive *);
extern int archive_read_support_compression_xz(struct archive *);
#endif

extern int archive_read_support_filter_all(struct archive *);
extern int archive_read_support_filter_bzip2(struct archive *);
extern int archive_read_support_filter_compress(struct archive *);
extern int archive_read_support_filter_gzip(struct archive *);
extern int archive_read_support_filter_grzip(struct archive *);
extern int archive_read_support_filter_lrzip(struct archive *);
extern int archive_read_support_filter_lz4(struct archive *);
extern int archive_read_support_filter_lzip(struct archive *);
extern int archive_read_support_filter_lzma(struct archive *);
extern int archive_read_support_filter_lzop(struct archive *);
extern int archive_read_support_filter_none(struct archive *);
extern int archive_read_support_filter_program(struct archive *,
const char *command);
extern int archive_read_support_filter_program_signature
(struct archive *, const char * /* cmd */,
const void * /* match */, size_t);
extern int archive_read_support_filter_rpm(struct archive *);
extern int archive_read_support_filter_uu(struct archive *);
extern int archive_read_support_filter_xz(struct archive *);

/* FORMATS */
extern int archive_read_support_format_all(struct archive *);
extern int archive_read_support_format_7zip(struct archive *);
extern int archive_read_support_format_all(struct archive *);
extern int archive_read_support_format_ar(struct archive *);
extern int archive_read_support_format_by_code(struct archive *, int);
extern int archive_read_support_format_cab(struct archive *);
extern int archive_read_support_format_cpio(struct archive *);
extern int archive_read_support_format_empty(struct archive *);
extern int archive_read_support_format_gnutar(struct archive *);
extern int archive_read_support_format_iso9660(struct archive *);
extern int archive_read_support_format_lha(struct archive *);
/*extern int archive_read_support_format_mtree(struct archive *);*/
/* extern int archive_read_support_format_mtree(struct archive *); */
extern int archive_read_support_format_rar(struct archive *);
extern int archive_read_support_format_raw(struct archive *);
extern int archive_read_support_format_tar(struct archive *);
extern int archive_read_support_format_warc(struct archive *);
extern int archive_read_support_format_xar(struct archive *);
/* archive_read_support_format_zip() enables both streamable and seekable
* zip readers. */
extern int archive_read_support_format_zip(struct archive *);
/*extern int archive_read_support_format_by_code(struct archive *, int);*/
/* Reads Zip archives as stream from beginning to end. Doesn't
* correctly handle SFX ZIP files or ZIP archives that have been modified
* in-place. */
extern int archive_read_support_format_zip_streamable(struct archive *);
/* Reads starting from central directory; requires seekable input. */
extern int archive_read_support_format_zip_seekable(struct archive *);

/* Functions to manually set the format and filters to be used. This is
* useful to bypass the bidding process when the format and filters to use
* is known in advance.
*/
extern int archive_read_set_format(struct archive *, int);
extern int archive_read_append_filter(struct archive *, int);
extern int archive_read_append_filter_program(struct archive *,
const char *);
extern int archive_read_append_filter_program_signature
(struct archive *, const char *, const void * /* match */, size_t);

/* ARCHIVE WRITING */
extern struct archive *archive_write_new(void);
@@ -227,42 +293,78 @@ extern int archive_write_close(struct archive *);
extern int archive_write_header(struct archive *,
struct archive_entry *);

extern int archive_write_set_format_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option to the filter only. */
extern int archive_write_set_filter_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option to both the format and the filter. */
extern int archive_write_set_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option string to both the format and the filter. */
extern int archive_write_set_options(struct archive *_a,
const char *opts);

/* password */
extern int archive_write_set_passphrase(struct archive *_a, const char *p);
/* data */

/* commit */
extern int archive_write_finish_entry(struct archive *);

/* FILTERS */
extern int archive_write_add_filter(struct archive *, int filter_code);
extern int archive_write_add_filter_by_name(struct archive *,
const char *name);
extern int archive_write_add_filter_b64encode(struct archive *);
extern int archive_write_add_filter_bzip2(struct archive *);
extern int archive_write_add_filter_compress(struct archive *);
extern int archive_write_add_filter_grzip(struct archive *);
extern int archive_write_add_filter_gzip(struct archive *);
extern int archive_write_add_filter_lrzip(struct archive *);
extern int archive_write_add_filter_lz4(struct archive *);
extern int archive_write_add_filter_lzip(struct archive *);
extern int archive_write_add_filter_lzma(struct archive *);
extern int archive_write_add_filter_lzop(struct archive *);
extern int archive_write_add_filter_none(struct archive *);
extern int archive_write_add_filter_program(struct archive *,
const char *cmd);
extern int archive_write_add_filter_uuencode(struct archive *);
extern int archive_write_add_filter_xz(struct archive *);


/* FORMATS */
/* A convenience function to set the format based on the code or name. */
extern int archive_write_set_format(struct archive *, int format_code);
extern int archive_write_set_format_by_name(struct archive *,
const char *name);
/* To minimize link pollution, use one or more of the following. */
extern int archive_write_set_format_7zip(struct archive *);
extern int archive_write_set_format_ar_bsd(struct archive *);
extern int archive_write_set_format_ar_svr4(struct archive *);
extern int archive_write_set_format_cpio(struct archive *);
extern int archive_write_set_format_cpio_newc(struct archive *);
extern int archive_write_set_format_gnutar(struct archive *);
extern int archive_write_set_format_iso9660(struct archive *);
/*extern int archive_write_set_format_mtree(struct archive *);*/
extern int archive_write_set_format_mtree(struct archive *);
extern int archive_write_set_format_mtree_classic(struct archive *);
/* TODO: int archive_write_set_format_old_tar(struct archive *); */
extern int archive_write_set_format_pax(struct archive *);
extern int archive_write_set_format_pax_restricted(struct archive *);
extern int archive_write_set_format_raw(struct archive *);
extern int archive_write_set_format_shar(struct archive *);
extern int archive_write_set_format_shar_dump(struct archive *);
extern int archive_write_set_format_ustar(struct archive *);
extern int archive_write_set_format_v7tar(struct archive *);
extern int archive_write_set_format_warc(struct archive *);
extern int archive_write_set_format_xar(struct archive *);
extern int archive_write_set_format_zip(struct archive *);
extern int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename);
extern int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext);
extern int archive_write_zip_set_compression_deflate(struct archive *);
extern int archive_write_zip_set_compression_store(struct archive *);

/* ARCHIVE ENTRY */
extern struct archive_entry *archive_entry_new(void);
@@ -276,6 +378,33 @@ extern __LA_INT64_T archive_entry_size(struct archive_entry *);
extern time_t archive_entry_mtime(struct archive_entry *);
extern __LA_MODE_T archive_entry_filetype(struct archive_entry *);
extern __LA_MODE_T archive_entry_perm(struct archive_entry *);
extern const char *archive_entry_symlink(struct archive_entry *);
//extern const char *archive_entry_symlink_utf8(struct archive_entry *);

extern void archive_entry_set_link(struct archive_entry *, const char *);
//extern void archive_entry_set_link_utf8(struct archive_entry *, const char *);
//extern int archive_entry_symlink_type(struct archive_entry *);
extern const wchar_t *archive_entry_symlink_w(struct archive_entry *);

//extern void archive_entry_copy_link(struct archive_entry *, const char *);
//extern void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);

/* The names for symlink modes here correspond to an old BSD
* command-line argument convention: -L, -P, -H */
/* Follow all symlinks. */
extern int archive_read_disk_set_symlink_logical(struct archive *);
/* Follow no symlinks. */
extern int archive_read_disk_set_symlink_physical(struct archive *);
/* Follow symlink initially, then not. */
extern int archive_read_disk_set_symlink_hybrid(struct archive *);


extern void archive_entry_set_symlink(struct archive_entry *, const char *);
//extern void archive_entry_set_symlink_type(struct archive_entry *, int);
//extern void archive_entry_set_symlink_utf8(struct archive_entry *, const char *);
extern void archive_entry_copy_symlink(struct archive_entry *, const char *);
extern void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
//extern int archive_entry_update_symlink_utf8(struct archive_entry *, const char *);

/* writing */
extern void archive_entry_set_pathname(struct archive_entry *, const char *);
@@ -283,16 +412,19 @@ extern void archive_entry_set_size(struct archive_entry *, __LA_INT64_T);
extern void archive_entry_set_mtime(struct archive_entry *, time_t, long);
extern void archive_entry_set_filetype(struct archive_entry *, unsigned int);
extern void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
//extern void archive_entry_set_link(struct archive_entry *, __LA_MODE_T);
//extern void archive_entry_set_symlink(struct archive_entry *, __LA_MODE_T);


/* ERROR HANDLING */
extern int archive_errno(struct archive *);
extern const char *archive_error_string(struct archive *);

extern int archive_version_number(void);
extern const char *archive_version_string(void);

/* CONSTANTS */
#define ARCHIVE_VERSION_NUMBER 3000001
#define ARCHIVE_VERSION_STRING "libarchive 3.0.1b"

#define ARCHIVE_EOF 1 /* Found end of archive. */
#define ARCHIVE_OK 0 /* Operation was successful. */
#define ARCHIVE_RETRY (-10) /* Retry might succeed. */
@@ -310,6 +442,10 @@ extern const char *archive_error_string(struct archive *);
#define ARCHIVE_FILTER_UU 7
#define ARCHIVE_FILTER_RPM 8
#define ARCHIVE_FILTER_LZIP 9
#define ARCHIVE_FILTER_LRZIP 10
#define ARCHIVE_FILTER_LZOP 11
#define ARCHIVE_FILTER_GRZIP 12
#define ARCHIVE_FILTER_LZ4 13

#define ARCHIVE_FORMAT_BASE_MASK 0xff0000
#define ARCHIVE_FORMAT_CPIO 0x10000
@@ -341,30 +477,59 @@ extern const char *archive_error_string(struct archive *);
#define ARCHIVE_FORMAT_CAB 0xC0000
#define ARCHIVE_FORMAT_RAR 0xD0000
#define ARCHIVE_FORMAT_7ZIP 0xE0000
#define ARCHIVE_FORMAT_WARC 0xF0000

/* Default: Do not try to set owner/group. */
#define ARCHIVE_EXTRACT_OWNER (0x0001)
/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
#define ARCHIVE_EXTRACT_PERM (0x0002)
/* Default: Do not restore mtime/atime. */
#define ARCHIVE_EXTRACT_TIME (0x0004)
/* Default: Replace existing files. */
#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008)
/* Default: Try create first, unlink only if create fails with EEXIST. */
#define ARCHIVE_EXTRACT_UNLINK (0x0010)
/* Default: Do not restore ACLs. */
#define ARCHIVE_EXTRACT_ACL (0x0020)
/* Default: Do not restore fflags. */
#define ARCHIVE_EXTRACT_FFLAGS (0x0040)
/* Default: Do not restore xattrs. */
#define ARCHIVE_EXTRACT_XATTR (0x0080)
/* Default: Do not try to guard against extracts redirected by symlinks. */
/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100)
/* Default: Do not reject entries with '..' as path elements. */
#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200)
/* Default: Create parent directories as needed. */
#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400)
/* Default: Overwrite files, even if one on disk is newer. */
#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800)
/* Detect blocks of 0 and write holes instead. */
#define ARCHIVE_EXTRACT_SPARSE (0x1000)
/* Default: Do not restore Mac extended metadata. */
/* This has no effect except on Mac OS. */
#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000)
/* Default: Use HFS+ compression if it was compressed. */
/* This has no effect except on Mac OS v10.6 or later. */
#define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000)
/* Default: Do not use HFS+ compression if it was not compressed. */
/* This has no effect except on Mac OS v10.6 or later. */
#define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000)
/* Default: Do not reject entries with absolute paths */
#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
/* Default: Do not clear no-change flags when unlinking object */
#define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000)


%inline %{

PyObject *archive_read_data_into_str(struct archive *archive, int len) {
PyObject *str = NULL;
if (!(str = PyUnicode_FromStringAndSize(NULL, len))) {
if (!(str = PyBytes_FromStringAndSize(NULL, len))) {
PyErr_SetString(PyExc_MemoryError, "could not allocate string.");
return NULL;
}
if (len != archive_read_data(archive, PyString_AS_STRING(str), len)) {
if (len != archive_read_data(archive, PyBytes_AS_STRING(str), len)) {
PyErr_SetString(PyExc_RuntimeError, "could not read requested data.");
return NULL;
}
@@ -372,8 +537,9 @@ PyObject *archive_read_data_into_str(struct archive *archive, int len) {
}

PyObject *archive_write_data_from_str(struct archive *archive, PyObject *str) {
int len = PyString_Size(str);
if (!archive_write_data(archive, PyString_AS_STRING(str), len)) {
Py_ssize_t len = PyBytes_Size(str);
if (!archive_write_data(archive, PyBytes_AS_STRING(str), len)) {
PyErr_SetString(PyExc_RuntimeError, "could not write requested data.");
return NULL;
}


+ 438
- 326
libarchive/_libarchive.py View File

@@ -1,410 +1,516 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.4
# Version 4.0.2
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.

from sys import version_info as _swig_python_version_info
if _swig_python_version_info < (2, 7, 0):
raise RuntimeError("Python 2.7 or later required")


from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('__libarchive', [dirname(__file__)])
except ImportError:
import __libarchive
return __libarchive
if fp is not None:
try:
_mod = imp.load_module('__libarchive', fp, pathname, description)
finally:
fp.close()
return _mod
__libarchive = swig_import_helper()
del swig_import_helper
# Import the low-level C/C++ module
if __package__ or "." in __name__:
from . import __libarchive
else:
import __libarchive
del version_info

try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
import builtins as __builtin__
except ImportError:
import __builtin__

def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0

def _swig_setattr_nondynamic_instance_variable(set):
def set_instance_attr(self, name, value):
if name == "thisown":
self.this.own(value)
elif name == "this":
set(self, name, value)
elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
set(self, name, value)
else:
raise AttributeError("You cannot add instance attributes to %s" % self)
return set_instance_attr


def _swig_setattr_nondynamic_class_variable(set):
def set_class_attr(cls, name, value):
if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
set(cls, name, value)
else:
raise AttributeError("You cannot add class attributes to %s" % cls)
return set_class_attr


def _swig_add_metaclass(metaclass):
"""Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
def wrapper(cls):
return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
return wrapper


class _SwigNonDynamicMeta(type):
"""Meta class to enforce nondynamic attributes (no new attributes) for a class"""
__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)



def archive_read_new():
return __libarchive.archive_read_new()
archive_read_new = __libarchive.archive_read_new
return __libarchive.archive_read_new()

def archive_read_free(arg1):
return __libarchive.archive_read_free(arg1)

def archive_read_open_filename(arg1, _filename, _block_size):
return __libarchive.archive_read_open_filename(arg1, _filename, _block_size)

def archive_read_open_memory(arg1, buff, size):
return __libarchive.archive_read_open_memory(arg1, buff, size)

def archive_read_open_memory2(a, buff, size, read_size):
return __libarchive.archive_read_open_memory2(a, buff, size, read_size)

def archive_read_open_fd(arg1, _fd, _block_size):
return __libarchive.archive_read_open_fd(arg1, _fd, _block_size)

def archive_read_close(arg1):
return __libarchive.archive_read_close(arg1)

def archive_format(arg1):
return __libarchive.archive_format(arg1)

def archive_read_next_header2(arg1, arg2):
return __libarchive.archive_read_next_header2(arg1, arg2)

def archive_entry_stat(arg1):
return __libarchive.archive_entry_stat(arg1)

def archive_read_header_position(arg1):
return __libarchive.archive_read_header_position(arg1)

def archive_read_set_format_option(_a, m, o, v):
return __libarchive.archive_read_set_format_option(_a, m, o, v)

def archive_read_set_filter_option(_a, m, o, v):
return __libarchive.archive_read_set_filter_option(_a, m, o, v)

def archive_read_set_option(_a, m, o, v):
return __libarchive.archive_read_set_option(_a, m, o, v)

def archive_read_free(*args):
return __libarchive.archive_read_free(*args)
archive_read_free = __libarchive.archive_read_free
def archive_read_set_options(_a, opts):
return __libarchive.archive_read_set_options(_a, opts)

def archive_read_open_filename(*args):
return __libarchive.archive_read_open_filename(*args)
archive_read_open_filename = __libarchive.archive_read_open_filename
def archive_read_add_passphrase(arg1, arg2):
return __libarchive.archive_read_add_passphrase(arg1, arg2)

def archive_read_open_memory(*args):
return __libarchive.archive_read_open_memory(*args)
archive_read_open_memory = __libarchive.archive_read_open_memory
def archive_read_data_skip(arg1):
return __libarchive.archive_read_data_skip(arg1)

def archive_read_open_memory2(*args):
return __libarchive.archive_read_open_memory2(*args)
archive_read_open_memory2 = __libarchive.archive_read_open_memory2
def archive_read_data_into_fd(arg1, fd):
return __libarchive.archive_read_data_into_fd(arg1, fd)

def archive_read_open_fd(*args):
return __libarchive.archive_read_open_fd(*args)
archive_read_open_fd = __libarchive.archive_read_open_fd
def archive_read_support_compression_all(arg1):
return __libarchive.archive_read_support_compression_all(arg1)

def archive_read_close(*args):
return __libarchive.archive_read_close(*args)
archive_read_close = __libarchive.archive_read_close
def archive_read_support_compression_bzip2(arg1):
return __libarchive.archive_read_support_compression_bzip2(arg1)

def archive_format(*args):
return __libarchive.archive_format(*args)
archive_format = __libarchive.archive_format
def archive_read_support_compression_compress(arg1):
return __libarchive.archive_read_support_compression_compress(arg1)

def archive_read_next_header2(*args):
return __libarchive.archive_read_next_header2(*args)
archive_read_next_header2 = __libarchive.archive_read_next_header2
def archive_read_support_compression_gzip(arg1):
return __libarchive.archive_read_support_compression_gzip(arg1)

def archive_entry_stat(*args):
return __libarchive.archive_entry_stat(*args)
archive_entry_stat = __libarchive.archive_entry_stat
def archive_read_support_compression_lzip(arg1):
return __libarchive.archive_read_support_compression_lzip(arg1)

def archive_read_header_position(*args):
return __libarchive.archive_read_header_position(*args)
archive_read_header_position = __libarchive.archive_read_header_position
def archive_read_support_compression_lzma(arg1):
return __libarchive.archive_read_support_compression_lzma(arg1)

def archive_read_data_skip(*args):
return __libarchive.archive_read_data_skip(*args)
archive_read_data_skip = __libarchive.archive_read_data_skip
def archive_read_support_compression_none(arg1):
return __libarchive.archive_read_support_compression_none(arg1)

def archive_read_data_into_fd(*args):
return __libarchive.archive_read_data_into_fd(*args)
archive_read_data_into_fd = __libarchive.archive_read_data_into_fd
def archive_read_support_compression_program(arg1, command):
return __libarchive.archive_read_support_compression_program(arg1, command)

def archive_read_support_filter_all(*args):
return __libarchive.archive_read_support_filter_all(*args)
archive_read_support_filter_all = __libarchive.archive_read_support_filter_all
def archive_read_support_compression_program_signature(arg1, arg2, arg3, arg4):
return __libarchive.archive_read_support_compression_program_signature(arg1, arg2, arg3, arg4)

def archive_read_support_filter_bzip2(*args):
return __libarchive.archive_read_support_filter_bzip2(*args)
archive_read_support_filter_bzip2 = __libarchive.archive_read_support_filter_bzip2
def archive_read_support_compression_rpm(arg1):
return __libarchive.archive_read_support_compression_rpm(arg1)

def archive_read_support_filter_compress(*args):
return __libarchive.archive_read_support_filter_compress(*args)
archive_read_support_filter_compress = __libarchive.archive_read_support_filter_compress
def archive_read_support_compression_uu(arg1):
return __libarchive.archive_read_support_compression_uu(arg1)

def archive_read_support_filter_gzip(*args):
return __libarchive.archive_read_support_filter_gzip(*args)
archive_read_support_filter_gzip = __libarchive.archive_read_support_filter_gzip
def archive_read_support_compression_xz(arg1):
return __libarchive.archive_read_support_compression_xz(arg1)

def archive_read_support_filter_lzip(*args):
return __libarchive.archive_read_support_filter_lzip(*args)
archive_read_support_filter_lzip = __libarchive.archive_read_support_filter_lzip
def archive_read_support_filter_all(arg1):
return __libarchive.archive_read_support_filter_all(arg1)

def archive_read_support_filter_lzma(*args):
return __libarchive.archive_read_support_filter_lzma(*args)
archive_read_support_filter_lzma = __libarchive.archive_read_support_filter_lzma
def archive_read_support_filter_bzip2(arg1):
return __libarchive.archive_read_support_filter_bzip2(arg1)

def archive_read_support_filter_none(*args):
return __libarchive.archive_read_support_filter_none(*args)
archive_read_support_filter_none = __libarchive.archive_read_support_filter_none
def archive_read_support_filter_compress(arg1):
return __libarchive.archive_read_support_filter_compress(arg1)

def archive_read_support_filter_rpm(*args):
return __libarchive.archive_read_support_filter_rpm(*args)
archive_read_support_filter_rpm = __libarchive.archive_read_support_filter_rpm
def archive_read_support_filter_gzip(arg1):
return __libarchive.archive_read_support_filter_gzip(arg1)

def archive_read_support_filter_uu(*args):
return __libarchive.archive_read_support_filter_uu(*args)
archive_read_support_filter_uu = __libarchive.archive_read_support_filter_uu
def archive_read_support_filter_grzip(arg1):
return __libarchive.archive_read_support_filter_grzip(arg1)

def archive_read_support_filter_xz(*args):
return __libarchive.archive_read_support_filter_xz(*args)
archive_read_support_filter_xz = __libarchive.archive_read_support_filter_xz
def archive_read_support_filter_lrzip(arg1):
return __libarchive.archive_read_support_filter_lrzip(arg1)

def archive_read_support_format_all(*args):
return __libarchive.archive_read_support_format_all(*args)
archive_read_support_format_all = __libarchive.archive_read_support_format_all
def archive_read_support_filter_lz4(arg1):
return __libarchive.archive_read_support_filter_lz4(arg1)

def archive_read_support_format_7zip(*args):
return __libarchive.archive_read_support_format_7zip(*args)
archive_read_support_format_7zip = __libarchive.archive_read_support_format_7zip
def archive_read_support_filter_lzip(arg1):
return __libarchive.archive_read_support_filter_lzip(arg1)

def archive_read_support_format_ar(*args):
return __libarchive.archive_read_support_format_ar(*args)
archive_read_support_format_ar = __libarchive.archive_read_support_format_ar
def archive_read_support_filter_lzma(arg1):
return __libarchive.archive_read_support_filter_lzma(arg1)

def archive_read_support_format_cab(*args):
return __libarchive.archive_read_support_format_cab(*args)
archive_read_support_format_cab = __libarchive.archive_read_support_format_cab
def archive_read_support_filter_lzop(arg1):
return __libarchive.archive_read_support_filter_lzop(arg1)

def archive_read_support_format_cpio(*args):
return __libarchive.archive_read_support_format_cpio(*args)
archive_read_support_format_cpio = __libarchive.archive_read_support_format_cpio
def archive_read_support_filter_none(arg1):
return __libarchive.archive_read_support_filter_none(arg1)

def archive_read_support_format_empty(*args):
return __libarchive.archive_read_support_format_empty(*args)
archive_read_support_format_empty = __libarchive.archive_read_support_format_empty
def archive_read_support_filter_program(arg1, command):
return __libarchive.archive_read_support_filter_program(arg1, command)

def archive_read_support_format_gnutar(*args):
return __libarchive.archive_read_support_format_gnutar(*args)
archive_read_support_format_gnutar = __libarchive.archive_read_support_format_gnutar
def archive_read_support_filter_program_signature(arg1, arg2, arg3, arg4):
return __libarchive.archive_read_support_filter_program_signature(arg1, arg2, arg3, arg4)

def archive_read_support_format_iso9660(*args):
return __libarchive.archive_read_support_format_iso9660(*args)
archive_read_support_format_iso9660 = __libarchive.archive_read_support_format_iso9660
def archive_read_support_filter_rpm(arg1):
return __libarchive.archive_read_support_filter_rpm(arg1)

def archive_read_support_format_lha(*args):
return __libarchive.archive_read_support_format_lha(*args)
archive_read_support_format_lha = __libarchive.archive_read_support_format_lha
def archive_read_support_filter_uu(arg1):
return __libarchive.archive_read_support_filter_uu(arg1)

def archive_read_support_format_rar(*args):
return __libarchive.archive_read_support_format_rar(*args)
archive_read_support_format_rar = __libarchive.archive_read_support_format_rar
def archive_read_support_filter_xz(arg1):
return __libarchive.archive_read_support_filter_xz(arg1)

def archive_read_support_format_raw(*args):
return __libarchive.archive_read_support_format_raw(*args)
archive_read_support_format_raw = __libarchive.archive_read_support_format_raw
def archive_read_support_format_7zip(arg1):
return __libarchive.archive_read_support_format_7zip(arg1)

def archive_read_support_format_tar(*args):
return __libarchive.archive_read_support_format_tar(*args)
archive_read_support_format_tar = __libarchive.archive_read_support_format_tar
def archive_read_support_format_all(arg1):
return __libarchive.archive_read_support_format_all(arg1)

def archive_read_support_format_xar(*args):
return __libarchive.archive_read_support_format_xar(*args)
archive_read_support_format_xar = __libarchive.archive_read_support_format_xar
def archive_read_support_format_ar(arg1):
return __libarchive.archive_read_support_format_ar(arg1)

def archive_read_support_format_zip(*args):
return __libarchive.archive_read_support_format_zip(*args)
archive_read_support_format_zip = __libarchive.archive_read_support_format_zip
def archive_read_support_format_by_code(arg1, arg2):
return __libarchive.archive_read_support_format_by_code(arg1, arg2)

def archive_read_support_format_cab(arg1):
return __libarchive.archive_read_support_format_cab(arg1)

def archive_read_support_format_cpio(arg1):
return __libarchive.archive_read_support_format_cpio(arg1)

def archive_read_support_format_empty(arg1):
return __libarchive.archive_read_support_format_empty(arg1)

def archive_read_support_format_gnutar(arg1):
return __libarchive.archive_read_support_format_gnutar(arg1)

def archive_read_support_format_iso9660(arg1):
return __libarchive.archive_read_support_format_iso9660(arg1)

def archive_read_support_format_lha(arg1):
return __libarchive.archive_read_support_format_lha(arg1)

def archive_read_support_format_rar(arg1):
return __libarchive.archive_read_support_format_rar(arg1)

def archive_read_support_format_raw(arg1):
return __libarchive.archive_read_support_format_raw(arg1)

def archive_read_support_format_tar(arg1):
return __libarchive.archive_read_support_format_tar(arg1)

def archive_read_support_format_warc(arg1):
return __libarchive.archive_read_support_format_warc(arg1)

def archive_read_support_format_xar(arg1):
return __libarchive.archive_read_support_format_xar(arg1)

def archive_read_support_format_zip(arg1):
return __libarchive.archive_read_support_format_zip(arg1)

def archive_read_support_format_zip_streamable(arg1):
return __libarchive.archive_read_support_format_zip_streamable(arg1)

def archive_read_support_format_zip_seekable(arg1):
return __libarchive.archive_read_support_format_zip_seekable(arg1)

def archive_read_set_format(arg1, arg2):
return __libarchive.archive_read_set_format(arg1, arg2)

def archive_read_append_filter(arg1, arg2):
return __libarchive.archive_read_append_filter(arg1, arg2)

def archive_read_append_filter_program(arg1, arg2):
return __libarchive.archive_read_append_filter_program(arg1, arg2)

def archive_read_append_filter_program_signature(arg1, arg2, arg3, arg4):
return __libarchive.archive_read_append_filter_program_signature(arg1, arg2, arg3, arg4)

def archive_write_new():
return __libarchive.archive_write_new()
archive_write_new = __libarchive.archive_write_new
return __libarchive.archive_write_new()

def archive_write_free(arg1):
return __libarchive.archive_write_free(arg1)

def archive_write_open(arg1, arg2, arg3, arg4, arg5):
return __libarchive.archive_write_open(arg1, arg2, arg3, arg4, arg5)

def archive_write_open_fd(arg1, _fd):
return __libarchive.archive_write_open_fd(arg1, _fd)

def archive_write_open_filename(arg1, _file):
return __libarchive.archive_write_open_filename(arg1, _file)

def archive_write_free(*args):
return __libarchive.archive_write_free(*args)
archive_write_free = __libarchive.archive_write_free
def archive_write_open_filename_w(arg1, _file):
return __libarchive.archive_write_open_filename_w(arg1, _file)

def archive_write_open(*args):
return __libarchive.archive_write_open(*args)
archive_write_open = __libarchive.archive_write_open
def archive_write_open_memory(arg1, _buffer, _buffSize, _used):
return __libarchive.archive_write_open_memory(arg1, _buffer, _buffSize, _used)

def archive_write_open_fd(*args):
return __libarchive.archive_write_open_fd(*args)
archive_write_open_fd = __libarchive.archive_write_open_fd
def archive_write_close(arg1):
return __libarchive.archive_write_close(arg1)

def archive_write_open_filename(*args):
return __libarchive.archive_write_open_filename(*args)
archive_write_open_filename = __libarchive.archive_write_open_filename
def archive_write_header(arg1, arg2):
return __libarchive.archive_write_header(arg1, arg2)

def archive_write_open_filename_w(*args):
return __libarchive.archive_write_open_filename_w(*args)
archive_write_open_filename_w = __libarchive.archive_write_open_filename_w
def archive_write_set_format_option(_a, m, o, v):
return __libarchive.archive_write_set_format_option(_a, m, o, v)

def archive_write_open_memory(*args):
return __libarchive.archive_write_open_memory(*args)
archive_write_open_memory = __libarchive.archive_write_open_memory
def archive_write_set_filter_option(_a, m, o, v):
return __libarchive.archive_write_set_filter_option(_a, m, o, v)

def archive_write_close(*args):
return __libarchive.archive_write_close(*args)
archive_write_close = __libarchive.archive_write_close
def archive_write_set_option(_a, m, o, v):
return __libarchive.archive_write_set_option(_a, m, o, v)

def archive_write_header(*args):
return __libarchive.archive_write_header(*args)
archive_write_header = __libarchive.archive_write_header
def archive_write_set_options(_a, opts):
return __libarchive.archive_write_set_options(_a, opts)

def archive_write_finish_entry(*args):
return __libarchive.archive_write_finish_entry(*args)
archive_write_finish_entry = __libarchive.archive_write_finish_entry
def archive_write_set_passphrase(_a, p):
return __libarchive.archive_write_set_passphrase(_a, p)

def archive_write_add_filter_bzip2(*args):
return __libarchive.archive_write_add_filter_bzip2(*args)
archive_write_add_filter_bzip2 = __libarchive.archive_write_add_filter_bzip2
def archive_write_finish_entry(arg1):
return __libarchive.archive_write_finish_entry(arg1)

def archive_write_add_filter_compress(*args):
return __libarchive.archive_write_add_filter_compress(*args)
archive_write_add_filter_compress = __libarchive.archive_write_add_filter_compress
def archive_write_add_filter(arg1, filter_code):
return __libarchive.archive_write_add_filter(arg1, filter_code)

def archive_write_add_filter_gzip(*args):
return __libarchive.archive_write_add_filter_gzip(*args)
archive_write_add_filter_gzip = __libarchive.archive_write_add_filter_gzip
def archive_write_add_filter_by_name(arg1, name):
return __libarchive.archive_write_add_filter_by_name(arg1, name)

def archive_write_add_filter_lzip(*args):
return __libarchive.archive_write_add_filter_lzip(*args)
archive_write_add_filter_lzip = __libarchive.archive_write_add_filter_lzip
def archive_write_add_filter_b64encode(arg1):
return __libarchive.archive_write_add_filter_b64encode(arg1)

def archive_write_add_filter_lzma(*args):
return __libarchive.archive_write_add_filter_lzma(*args)
archive_write_add_filter_lzma = __libarchive.archive_write_add_filter_lzma
def archive_write_add_filter_bzip2(arg1):
return __libarchive.archive_write_add_filter_bzip2(arg1)

def archive_write_add_filter_none(*args):
return __libarchive.archive_write_add_filter_none(*args)
archive_write_add_filter_none = __libarchive.archive_write_add_filter_none
def archive_write_add_filter_compress(arg1):
return __libarchive.archive_write_add_filter_compress(arg1)

def archive_write_add_filter_xz(*args):
return __libarchive.archive_write_add_filter_xz(*args)
archive_write_add_filter_xz = __libarchive.archive_write_add_filter_xz
def archive_write_add_filter_grzip(arg1):
return __libarchive.archive_write_add_filter_grzip(arg1)

def archive_write_set_format(*args):
return __libarchive.archive_write_set_format(*args)
archive_write_set_format = __libarchive.archive_write_set_format
def archive_write_add_filter_gzip(arg1):
return __libarchive.archive_write_add_filter_gzip(arg1)

def archive_write_set_format_by_name(*args):
return __libarchive.archive_write_set_format_by_name(*args)
archive_write_set_format_by_name = __libarchive.archive_write_set_format_by_name
def archive_write_add_filter_lrzip(arg1):
return __libarchive.archive_write_add_filter_lrzip(arg1)

def archive_write_set_format_ar_bsd(*args):
return __libarchive.archive_write_set_format_ar_bsd(*args)
archive_write_set_format_ar_bsd = __libarchive.archive_write_set_format_ar_bsd
def archive_write_add_filter_lz4(arg1):
return __libarchive.archive_write_add_filter_lz4(arg1)

def archive_write_set_format_ar_svr4(*args):
return __libarchive.archive_write_set_format_ar_svr4(*args)
archive_write_set_format_ar_svr4 = __libarchive.archive_write_set_format_ar_svr4
def archive_write_add_filter_lzip(arg1):
return __libarchive.archive_write_add_filter_lzip(arg1)

def archive_write_set_format_cpio(*args):
return __libarchive.archive_write_set_format_cpio(*args)
archive_write_set_format_cpio = __libarchive.archive_write_set_format_cpio
def archive_write_add_filter_lzma(arg1):
return __libarchive.archive_write_add_filter_lzma(arg1)

def archive_write_set_format_cpio_newc(*args):
return __libarchive.archive_write_set_format_cpio_newc(*args)
archive_write_set_format_cpio_newc = __libarchive.archive_write_set_format_cpio_newc
def archive_write_add_filter_lzop(arg1):
return __libarchive.archive_write_add_filter_lzop(arg1)

def archive_write_set_format_gnutar(*args):
return __libarchive.archive_write_set_format_gnutar(*args)
archive_write_set_format_gnutar = __libarchive.archive_write_set_format_gnutar
def archive_write_add_filter_none(arg1):
return __libarchive.archive_write_add_filter_none(arg1)

def archive_write_set_format_iso9660(*args):
return __libarchive.archive_write_set_format_iso9660(*args)
archive_write_set_format_iso9660 = __libarchive.archive_write_set_format_iso9660
def archive_write_add_filter_program(arg1, cmd):
return __libarchive.archive_write_add_filter_program(arg1, cmd)

def archive_write_set_format_pax(*args):
return __libarchive.archive_write_set_format_pax(*args)
archive_write_set_format_pax = __libarchive.archive_write_set_format_pax
def archive_write_add_filter_uuencode(arg1):
return __libarchive.archive_write_add_filter_uuencode(arg1)

def archive_write_set_format_pax_restricted(*args):
return __libarchive.archive_write_set_format_pax_restricted(*args)
archive_write_set_format_pax_restricted = __libarchive.archive_write_set_format_pax_restricted
def archive_write_add_filter_xz(arg1):
return __libarchive.archive_write_add_filter_xz(arg1)

def archive_write_set_format_shar(*args):
return __libarchive.archive_write_set_format_shar(*args)
archive_write_set_format_shar = __libarchive.archive_write_set_format_shar
def archive_write_set_format(arg1, format_code):
return __libarchive.archive_write_set_format(arg1, format_code)

def archive_write_set_format_shar_dump(*args):
return __libarchive.archive_write_set_format_shar_dump(*args)
archive_write_set_format_shar_dump = __libarchive.archive_write_set_format_shar_dump
def archive_write_set_format_by_name(arg1, name):
return __libarchive.archive_write_set_format_by_name(arg1, name)

def archive_write_set_format_ustar(*args):
return __libarchive.archive_write_set_format_ustar(*args)
archive_write_set_format_ustar = __libarchive.archive_write_set_format_ustar
def archive_write_set_format_7zip(arg1):
return __libarchive.archive_write_set_format_7zip(arg1)

def archive_write_set_format_xar(*args):
return __libarchive.archive_write_set_format_xar(*args)
archive_write_set_format_xar = __libarchive.archive_write_set_format_xar
def archive_write_set_format_ar_bsd(arg1):
return __libarchive.archive_write_set_format_ar_bsd(arg1)

def archive_write_set_format_zip(*args):
return __libarchive.archive_write_set_format_zip(*args)
archive_write_set_format_zip = __libarchive.archive_write_set_format_zip
def archive_write_set_format_ar_svr4(arg1):
return __libarchive.archive_write_set_format_ar_svr4(arg1)

def archive_write_set_format_cpio(arg1):
return __libarchive.archive_write_set_format_cpio(arg1)

def archive_write_set_format_cpio_newc(arg1):
return __libarchive.archive_write_set_format_cpio_newc(arg1)

def archive_write_set_format_gnutar(arg1):
return __libarchive.archive_write_set_format_gnutar(arg1)

def archive_write_set_format_iso9660(arg1):
return __libarchive.archive_write_set_format_iso9660(arg1)

def archive_write_set_format_mtree(arg1):
return __libarchive.archive_write_set_format_mtree(arg1)

def archive_write_set_format_mtree_classic(arg1):
return __libarchive.archive_write_set_format_mtree_classic(arg1)

def archive_write_set_format_pax(arg1):
return __libarchive.archive_write_set_format_pax(arg1)

def archive_write_set_format_pax_restricted(arg1):
return __libarchive.archive_write_set_format_pax_restricted(arg1)

def archive_write_set_format_raw(arg1):
return __libarchive.archive_write_set_format_raw(arg1)

def archive_write_set_format_shar(arg1):
return __libarchive.archive_write_set_format_shar(arg1)

def archive_write_set_format_shar_dump(arg1):
return __libarchive.archive_write_set_format_shar_dump(arg1)

def archive_write_set_format_ustar(arg1):
return __libarchive.archive_write_set_format_ustar(arg1)

def archive_write_set_format_v7tar(arg1):
return __libarchive.archive_write_set_format_v7tar(arg1)

def archive_write_set_format_warc(arg1):
return __libarchive.archive_write_set_format_warc(arg1)

def archive_write_set_format_xar(arg1):
return __libarchive.archive_write_set_format_xar(arg1)

def archive_write_set_format_zip(arg1):
return __libarchive.archive_write_set_format_zip(arg1)

def archive_write_set_format_filter_by_ext(a, filename):
return __libarchive.archive_write_set_format_filter_by_ext(a, filename)

def archive_write_set_format_filter_by_ext_def(a, filename, def_ext):
return __libarchive.archive_write_set_format_filter_by_ext_def(a, filename, def_ext)

def archive_write_zip_set_compression_deflate(arg1):
return __libarchive.archive_write_zip_set_compression_deflate(arg1)

def archive_write_zip_set_compression_store(arg1):
return __libarchive.archive_write_zip_set_compression_store(arg1)

def archive_entry_new():
return __libarchive.archive_entry_new()
archive_entry_new = __libarchive.archive_entry_new

def archive_entry_free(*args):
return __libarchive.archive_entry_free(*args)
archive_entry_free = __libarchive.archive_entry_free

def archive_entry_pathname(*args):
return __libarchive.archive_entry_pathname(*args)
archive_entry_pathname = __libarchive.archive_entry_pathname

def archive_entry_pathname_w(*args):
return __libarchive.archive_entry_pathname_w(*args)
archive_entry_pathname_w = __libarchive.archive_entry_pathname_w

def archive_entry_size(*args):
return __libarchive.archive_entry_size(*args)
archive_entry_size = __libarchive.archive_entry_size

def archive_entry_mtime(*args):
return __libarchive.archive_entry_mtime(*args)
archive_entry_mtime = __libarchive.archive_entry_mtime

def archive_entry_filetype(*args):
return __libarchive.archive_entry_filetype(*args)
archive_entry_filetype = __libarchive.archive_entry_filetype

def archive_entry_perm(*args):
return __libarchive.archive_entry_perm(*args)
archive_entry_perm = __libarchive.archive_entry_perm

def archive_entry_set_pathname(*args):
return __libarchive.archive_entry_set_pathname(*args)
archive_entry_set_pathname = __libarchive.archive_entry_set_pathname

def archive_entry_set_size(*args):
return __libarchive.archive_entry_set_size(*args)
archive_entry_set_size = __libarchive.archive_entry_set_size

def archive_entry_set_mtime(*args):
return __libarchive.archive_entry_set_mtime(*args)
archive_entry_set_mtime = __libarchive.archive_entry_set_mtime

def archive_entry_set_filetype(*args):
return __libarchive.archive_entry_set_filetype(*args)
archive_entry_set_filetype = __libarchive.archive_entry_set_filetype

def archive_entry_set_perm(*args):
return __libarchive.archive_entry_set_perm(*args)
archive_entry_set_perm = __libarchive.archive_entry_set_perm

def archive_errno(*args):
return __libarchive.archive_errno(*args)
archive_errno = __libarchive.archive_errno

def archive_error_string(*args):
return __libarchive.archive_error_string(*args)
archive_error_string = __libarchive.archive_error_string
ARCHIVE_VERSION_NUMBER = __libarchive.ARCHIVE_VERSION_NUMBER
ARCHIVE_VERSION_STRING = __libarchive.ARCHIVE_VERSION_STRING
return __libarchive.archive_entry_new()

def archive_entry_free(arg1):
return __libarchive.archive_entry_free(arg1)

def archive_entry_pathname(arg1):
return __libarchive.archive_entry_pathname(arg1)

def archive_entry_pathname_w(arg1):
return __libarchive.archive_entry_pathname_w(arg1)

def archive_entry_size(arg1):
return __libarchive.archive_entry_size(arg1)

def archive_entry_mtime(arg1):
return __libarchive.archive_entry_mtime(arg1)

def archive_entry_filetype(arg1):
return __libarchive.archive_entry_filetype(arg1)

def archive_entry_perm(arg1):
return __libarchive.archive_entry_perm(arg1)

def archive_entry_symlink(arg1):
return __libarchive.archive_entry_symlink(arg1)

def archive_entry_set_link(arg1, arg2):
return __libarchive.archive_entry_set_link(arg1, arg2)

def archive_entry_symlink_w(arg1):
return __libarchive.archive_entry_symlink_w(arg1)

def archive_read_disk_set_symlink_logical(arg1):
return __libarchive.archive_read_disk_set_symlink_logical(arg1)

def archive_read_disk_set_symlink_physical(arg1):
return __libarchive.archive_read_disk_set_symlink_physical(arg1)

def archive_read_disk_set_symlink_hybrid(arg1):
return __libarchive.archive_read_disk_set_symlink_hybrid(arg1)

def archive_entry_set_symlink(arg1, arg2):
return __libarchive.archive_entry_set_symlink(arg1, arg2)

def archive_entry_copy_symlink(arg1, arg2):
return __libarchive.archive_entry_copy_symlink(arg1, arg2)

def archive_entry_copy_symlink_w(arg1, arg2):
return __libarchive.archive_entry_copy_symlink_w(arg1, arg2)

def archive_entry_set_pathname(arg1, arg2):
return __libarchive.archive_entry_set_pathname(arg1, arg2)

def archive_entry_set_size(arg1, arg2):
return __libarchive.archive_entry_set_size(arg1, arg2)

def archive_entry_set_mtime(arg1, arg2, arg3):
return __libarchive.archive_entry_set_mtime(arg1, arg2, arg3)

def archive_entry_set_filetype(arg1, arg2):
return __libarchive.archive_entry_set_filetype(arg1, arg2)

def archive_entry_set_perm(arg1, arg2):
return __libarchive.archive_entry_set_perm(arg1, arg2)

def archive_errno(arg1):
return __libarchive.archive_errno(arg1)

def archive_error_string(arg1):
return __libarchive.archive_error_string(arg1)

def archive_version_number():
return __libarchive.archive_version_number()

def archive_version_string():
return __libarchive.archive_version_string()
ARCHIVE_EOF = __libarchive.ARCHIVE_EOF
ARCHIVE_OK = __libarchive.ARCHIVE_OK
ARCHIVE_RETRY = __libarchive.ARCHIVE_RETRY
@@ -421,6 +527,10 @@ ARCHIVE_FILTER_XZ = __libarchive.ARCHIVE_FILTER_XZ
ARCHIVE_FILTER_UU = __libarchive.ARCHIVE_FILTER_UU
ARCHIVE_FILTER_RPM = __libarchive.ARCHIVE_FILTER_RPM
ARCHIVE_FILTER_LZIP = __libarchive.ARCHIVE_FILTER_LZIP
ARCHIVE_FILTER_LRZIP = __libarchive.ARCHIVE_FILTER_LRZIP
ARCHIVE_FILTER_LZOP = __libarchive.ARCHIVE_FILTER_LZOP
ARCHIVE_FILTER_GRZIP = __libarchive.ARCHIVE_FILTER_GRZIP
ARCHIVE_FILTER_LZ4 = __libarchive.ARCHIVE_FILTER_LZ4
ARCHIVE_FORMAT_BASE_MASK = __libarchive.ARCHIVE_FORMAT_BASE_MASK
ARCHIVE_FORMAT_CPIO = __libarchive.ARCHIVE_FORMAT_CPIO
ARCHIVE_FORMAT_CPIO_POSIX = __libarchive.ARCHIVE_FORMAT_CPIO_POSIX
@@ -451,6 +561,7 @@ ARCHIVE_FORMAT_LHA = __libarchive.ARCHIVE_FORMAT_LHA
ARCHIVE_FORMAT_CAB = __libarchive.ARCHIVE_FORMAT_CAB
ARCHIVE_FORMAT_RAR = __libarchive.ARCHIVE_FORMAT_RAR
ARCHIVE_FORMAT_7ZIP = __libarchive.ARCHIVE_FORMAT_7ZIP
ARCHIVE_FORMAT_WARC = __libarchive.ARCHIVE_FORMAT_WARC
ARCHIVE_EXTRACT_OWNER = __libarchive.ARCHIVE_EXTRACT_OWNER
ARCHIVE_EXTRACT_PERM = __libarchive.ARCHIVE_EXTRACT_PERM
ARCHIVE_EXTRACT_TIME = __libarchive.ARCHIVE_EXTRACT_TIME
@@ -465,14 +576,15 @@ ARCHIVE_EXTRACT_NO_AUTODIR = __libarchive.ARCHIVE_EXTRACT_NO_AUTODIR
ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER = __libarchive.ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER
ARCHIVE_EXTRACT_SPARSE = __libarchive.ARCHIVE_EXTRACT_SPARSE
ARCHIVE_EXTRACT_MAC_METADATA = __libarchive.ARCHIVE_EXTRACT_MAC_METADATA
ARCHIVE_EXTRACT_NO_HFS_COMPRESSION = __libarchive.ARCHIVE_EXTRACT_NO_HFS_COMPRESSION
ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED = __libarchive.ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED
ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS = __libarchive.ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS = __libarchive.ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS

def archive_read_data_into_str(*args):
return __libarchive.archive_read_data_into_str(*args)
archive_read_data_into_str = __libarchive.archive_read_data_into_str
def archive_read_data_into_str(archive, len):
return __libarchive.archive_read_data_into_str(archive, len)

def archive_write_data_from_str(*args):
return __libarchive.archive_write_data_from_str(*args)
archive_write_data_from_str = __libarchive.archive_write_data_from_str
# This file is compatible with both classic and new-style classes.
def archive_write_data_from_str(archive, str):
return __libarchive.archive_write_data_from_str(archive, str)



+ 3428
- 1456
libarchive/_libarchive_wrap.c
File diff suppressed because it is too large
View File


+ 361
- 98
libarchive/archive.h View File

@@ -28,9 +28,20 @@
#ifndef ARCHIVE_H_INCLUDED
#define ARCHIVE_H_INCLUDED

/*
* The version number is expressed as a single integer that makes it
* easy to compare versions at build time: for version a.b.c, the
* version number is printf("%d%03d%03d",a,b,c). For example, if you
* know your application requires version 2.12.108 or later, you can
* assert that ARCHIVE_VERSION_NUMBER >= 2012108.
*/
/* Note: Compiler will complain if this does not match archive_entry.h! */
#define ARCHIVE_VERSION_NUMBER 3005003

#include <sys/stat.h>
#include <stddef.h> /* for wchar_t */
#include <stdio.h> /* For FILE * */
#include <time.h> /* For time_t */

/*
* Note: archive.h is for use outside of libarchive; the configuration
@@ -41,29 +52,53 @@
*/
#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
# include <stdint.h>
#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS)
#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__) && !defined(__CLANG_INTTYPES_H)
# include <inttypes.h>
#endif

/* Get appropriate definitions of standard POSIX-style types. */
/* These should match the types used in 'struct stat' */
#if defined(_WIN32) && !defined(__CYGWIN__)
# define __LA_INT64_T __int64
# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
# define __LA_SSIZE_T ssize_t
# elif defined(_WIN64)
# define __LA_SSIZE_T __int64
# else
# define __LA_SSIZE_T long
/* Get appropriate definitions of 64-bit integer */
#if !defined(__LA_INT64_T_DEFINED)
/* Older code relied on the __LA_INT64_T macro; after 4.0 we'll switch to the typedef exclusively. */
# if ARCHIVE_VERSION_NUMBER < 4000000
#define __LA_INT64_T la_int64_t
# endif
#else
#define __LA_INT64_T_DEFINED
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
typedef __int64 la_int64_t;
# else
# include <unistd.h> /* ssize_t */
# if defined(_SCO_DS)
# define __LA_INT64_T long long
# if defined(_SCO_DS) || defined(__osf__)
typedef long long la_int64_t;
# else
typedef int64_t la_int64_t;
# endif
# endif
#endif

/* The la_ssize_t should match the type used in 'struct stat' */
#if !defined(__LA_SSIZE_T_DEFINED)
/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
# if ARCHIVE_VERSION_NUMBER < 4000000
#define __LA_SSIZE_T la_ssize_t
# endif
#define __LA_SSIZE_T_DEFINED
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
typedef ssize_t la_ssize_t;
# elif defined(_WIN64)
typedef __int64 la_ssize_t;
# else
typedef long la_ssize_t;
# endif
# else
# define __LA_INT64_T int64_t
# include <unistd.h> /* ssize_t */
typedef ssize_t la_ssize_t;
# endif
# define __LA_SSIZE_T ssize_t
#endif

/* Large file support for Android */
#ifdef __ANDROID__
#include "android_lf.h"
#endif

/*
@@ -97,6 +132,12 @@
#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */
#endif

#if defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 1
# define __LA_DEPRECATED __attribute__((deprecated))
#else
# define __LA_DEPRECATED
#endif

#ifdef __cplusplus
extern "C" {
#endif
@@ -109,24 +150,35 @@ extern "C" {
* header and library are very different, you should expect some
* strangeness. Don't do that.
*/

/*
* The version number is expressed as a single integer that makes it
* easy to compare versions at build time: for version a.b.c, the
* version number is printf("%d%03d%03d",a,b,c). For example, if you
* know your application requires version 2.12.108 or later, you can
* assert that ARCHIVE_VERSION_NUMBER >= 2012108.
*/
/* Note: Compiler will complain if this does not match archive_entry.h! */
#define ARCHIVE_VERSION_NUMBER 3000004
__LA_DECL int archive_version_number(void);

/*
* Textual name/version of the library, useful for version displays.
*/
#define ARCHIVE_VERSION_STRING "libarchive 3.0.4"
#define ARCHIVE_VERSION_ONLY_STRING "3.5.3"
#define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
__LA_DECL const char * archive_version_string(void);

/*
* Detailed textual name/version of the library and its dependencies.
* This has the form:
* "libarchive x.y.z zlib/a.b.c liblzma/d.e.f ... etc ..."
* the list of libraries described here will vary depending on how
* libarchive was compiled.
*/
__LA_DECL const char * archive_version_details(void);

/*
* Returns NULL if libarchive was compiled without the associated library.
* Otherwise, returns the version number that libarchive was compiled
* against.
*/
__LA_DECL const char * archive_zlib_version(void);
__LA_DECL const char * archive_liblzma_version(void);
__LA_DECL const char * archive_bzlib_version(void);
__LA_DECL const char * archive_liblz4_version(void);
__LA_DECL const char * archive_libzstd_version(void);

/* Declare our basic types. */
struct archive;
struct archive_entry;
@@ -167,7 +219,7 @@ struct archive_entry;
*/

/* Returns pointer and size of next block of data from archive. */
typedef __LA_SSIZE_T archive_read_callback(struct archive *,
typedef la_ssize_t archive_read_callback(struct archive *,
void *_client_data, const void **_buffer);

/* Skips at most request bytes from archive and returns the skipped amount.
@@ -175,18 +227,18 @@ typedef __LA_SSIZE_T archive_read_callback(struct archive *,
* If you do skip fewer bytes than requested, libarchive will invoke your
* read callback and discard data as necessary to make up the full skip.
*/
typedef __LA_INT64_T archive_skip_callback(struct archive *,
void *_client_data, __LA_INT64_T request);
typedef la_int64_t archive_skip_callback(struct archive *,
void *_client_data, la_int64_t request);

/* Seeks to specified location in the file and returns the position.
* Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h.
* Return ARCHIVE_FATAL if the seek fails for any reason.
*/
typedef __LA_INT64_T archive_seek_callback(struct archive *,
void *_client_data, __LA_INT64_T offset, int whence);
typedef la_int64_t archive_seek_callback(struct archive *,
void *_client_data, la_int64_t offset, int whence);

/* Returns size actually written, zero on EOF, -1 on error. */
typedef __LA_SSIZE_T archive_write_callback(struct archive *,
typedef la_ssize_t archive_write_callback(struct archive *,
void *_client_data,
const void *_buffer, size_t _length);

@@ -194,6 +246,22 @@ typedef int archive_open_callback(struct archive *, void *_client_data);

typedef int archive_close_callback(struct archive *, void *_client_data);

typedef int archive_free_callback(struct archive *, void *_client_data);

/* Switches from one client data object to the next/prev client data object.
* This is useful for reading from different data blocks such as a set of files
* that make up one large file.
*/
typedef int archive_switch_callback(struct archive *, void *_client_data1,
void *_client_data2);

/*
* Returns a passphrase used for encryption or decryption, NULL on nothing
* to do and give it up.
*/
typedef const char *archive_passphrase_callback(struct archive *,
void *_client_data);

/*
* Codes to identify various stream filters.
*/
@@ -207,6 +275,11 @@ typedef int archive_close_callback(struct archive *, void *_client_data);
#define ARCHIVE_FILTER_UU 7
#define ARCHIVE_FILTER_RPM 8
#define ARCHIVE_FILTER_LZIP 9
#define ARCHIVE_FILTER_LRZIP 10
#define ARCHIVE_FILTER_LZOP 11
#define ARCHIVE_FILTER_GRZIP 12
#define ARCHIVE_FILTER_LZ4 13
#define ARCHIVE_FILTER_ZSTD 14

#if ARCHIVE_VERSION_NUMBER < 4000000
#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE
@@ -219,6 +292,7 @@ typedef int archive_close_callback(struct archive *, void *_client_data);
#define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU
#define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM
#define ARCHIVE_COMPRESSION_LZIP ARCHIVE_FILTER_LZIP
#define ARCHIVE_COMPRESSION_LRZIP ARCHIVE_FILTER_LRZIP
#endif

/*
@@ -245,6 +319,7 @@ typedef int archive_close_callback(struct archive *, void *_client_data);
#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4)
#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5)
#define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6)
#define ARCHIVE_FORMAT_CPIO_PWB (ARCHIVE_FORMAT_CPIO | 7)
#define ARCHIVE_FORMAT_SHAR 0x20000
#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1)
#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2)
@@ -267,6 +342,32 @@ typedef int archive_close_callback(struct archive *, void *_client_data);
#define ARCHIVE_FORMAT_CAB 0xC0000
#define ARCHIVE_FORMAT_RAR 0xD0000
#define ARCHIVE_FORMAT_7ZIP 0xE0000
#define ARCHIVE_FORMAT_WARC 0xF0000
#define ARCHIVE_FORMAT_RAR_V5 0x100000

/*
* Codes returned by archive_read_format_capabilities().
*
* This list can be extended with values between 0 and 0xffff.
* The original purpose of this list was to let different archive
* format readers expose their general capabilities in terms of
* encryption.
*/
#define ARCHIVE_READ_FORMAT_CAPS_NONE (0) /* no special capabilities */
#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA (1<<0) /* reader can detect encrypted data */
#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA (1<<1) /* reader can detect encryptable metadata (pathname, mtime, etc.) */

/*
* Codes returned by archive_read_has_encrypted_entries().
*
* In case the archive does not support encryption detection at all
* ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. If the reader
* for some other reason (e.g. not enough bytes read) cannot say if
* there are encrypted entries, ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW
* is returned.
*/
#define ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED -2
#define ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW -1

/*-
* Basic outline for reading an archive:
@@ -278,7 +379,7 @@ typedef int archive_close_callback(struct archive *, void *_client_data);
* 4) Repeatedly call archive_read_next_header to get information about
* successive archive entries. Call archive_read_data to extract
* data for entries of interest.
* 5) Call archive_read_finish to end processing.
* 5) Call archive_read_free to end processing.
*/
__LA_DECL struct archive *archive_read_new(void);

@@ -291,40 +392,55 @@ __LA_DECL struct archive *archive_read_new(void);
*/

#if ARCHIVE_VERSION_NUMBER < 4000000
__LA_DECL int archive_read_support_compression_all(struct archive *);
__LA_DECL int archive_read_support_compression_bzip2(struct archive *);
__LA_DECL int archive_read_support_compression_compress(struct archive *);
__LA_DECL int archive_read_support_compression_gzip(struct archive *);
__LA_DECL int archive_read_support_compression_lzip(struct archive *);
__LA_DECL int archive_read_support_compression_lzma(struct archive *);
__LA_DECL int archive_read_support_compression_none(struct archive *);
__LA_DECL int archive_read_support_compression_all(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_bzip2(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_compress(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_gzip(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_lzip(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_lzma(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_none(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_program(struct archive *,
const char *command);
const char *command) __LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_program_signature
(struct archive *, const char *,
const void * /* match */, size_t);

__LA_DECL int archive_read_support_compression_rpm(struct archive *);
__LA_DECL int archive_read_support_compression_uu(struct archive *);
__LA_DECL int archive_read_support_compression_xz(struct archive *);
const void * /* match */, size_t) __LA_DEPRECATED;

__LA_DECL int archive_read_support_compression_rpm(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_uu(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_read_support_compression_xz(struct archive *)
__LA_DEPRECATED;
#endif

__LA_DECL int archive_read_support_filter_all(struct archive *);
__LA_DECL int archive_read_support_filter_by_code(struct archive *, int);
__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
__LA_DECL int archive_read_support_filter_compress(struct archive *);
__LA_DECL int archive_read_support_filter_gzip(struct archive *);
__LA_DECL int archive_read_support_filter_grzip(struct archive *);
__LA_DECL int archive_read_support_filter_lrzip(struct archive *);
__LA_DECL int archive_read_support_filter_lz4(struct archive *);
__LA_DECL int archive_read_support_filter_lzip(struct archive *);
__LA_DECL int archive_read_support_filter_lzma(struct archive *);
__LA_DECL int archive_read_support_filter_lzop(struct archive *);
__LA_DECL int archive_read_support_filter_none(struct archive *);
__LA_DECL int archive_read_support_filter_program(struct archive *,
const char *command);
__LA_DECL int archive_read_support_filter_program_signature
(struct archive *, const char *,
(struct archive *, const char * /* cmd */,
const void * /* match */, size_t);

__LA_DECL int archive_read_support_filter_rpm(struct archive *);
__LA_DECL int archive_read_support_filter_uu(struct archive *);
__LA_DECL int archive_read_support_filter_xz(struct archive *);
__LA_DECL int archive_read_support_filter_zstd(struct archive *);

__LA_DECL int archive_read_support_format_7zip(struct archive *);
__LA_DECL int archive_read_support_format_all(struct archive *);
@@ -338,10 +454,31 @@ __LA_DECL int archive_read_support_format_iso9660(struct archive *);
__LA_DECL int archive_read_support_format_lha(struct archive *);
__LA_DECL int archive_read_support_format_mtree(struct archive *);
__LA_DECL int archive_read_support_format_rar(struct archive *);
__LA_DECL int archive_read_support_format_rar5(struct archive *);
__LA_DECL int archive_read_support_format_raw(struct archive *);
__LA_DECL int archive_read_support_format_tar(struct archive *);
__LA_DECL int archive_read_support_format_warc(struct archive *);
__LA_DECL int archive_read_support_format_xar(struct archive *);
/* archive_read_support_format_zip() enables both streamable and seekable
* zip readers. */
__LA_DECL int archive_read_support_format_zip(struct archive *);
/* Reads Zip archives as stream from beginning to end. Doesn't
* correctly handle SFX ZIP files or ZIP archives that have been modified
* in-place. */
__LA_DECL int archive_read_support_format_zip_streamable(struct archive *);
/* Reads starting from central directory; requires seekable input. */
__LA_DECL int archive_read_support_format_zip_seekable(struct archive *);

/* Functions to manually set the format and filters to be used. This is
* useful to bypass the bidding process when the format and filters to use
* is known in advance.
*/
__LA_DECL int archive_read_set_format(struct archive *, int);
__LA_DECL int archive_read_append_filter(struct archive *, int);
__LA_DECL int archive_read_append_filter_program(struct archive *,
const char *);
__LA_DECL int archive_read_append_filter_program_signature
(struct archive *, const char *, const void * /* match */, size_t);

/* Set various callbacks. */
__LA_DECL int archive_read_set_open_callback(struct archive *,
@@ -354,8 +491,23 @@ __LA_DECL int archive_read_set_skip_callback(struct archive *,
archive_skip_callback *);
__LA_DECL int archive_read_set_close_callback(struct archive *,
archive_close_callback *);
/* The callback data is provided to all of the callbacks above. */
/* Callback used to switch between one data object to the next */
__LA_DECL int archive_read_set_switch_callback(struct archive *,
archive_switch_callback *);

/* This sets the first data object. */
__LA_DECL int archive_read_set_callback_data(struct archive *, void *);
/* This sets data object at specified index */
__LA_DECL int archive_read_set_callback_data2(struct archive *, void *,
unsigned int);
/* This adds a data object at the specified index. */
__LA_DECL int archive_read_add_callback_data(struct archive *, void *,
unsigned int);
/* This appends a data object to the end of list */
__LA_DECL int archive_read_append_callback_data(struct archive *, void *);
/* This prepends a data object to the beginning of list */
__LA_DECL int archive_read_prepend_callback_data(struct archive *, void *);

/* Opening freezes the callbacks. */
__LA_DECL int archive_read_open1(struct archive *);

@@ -375,16 +527,20 @@ __LA_DECL int archive_read_open2(struct archive *, void *_client_data,
/* Use this if you know the filename. Note: NULL indicates stdin. */
__LA_DECL int archive_read_open_filename(struct archive *,
const char *_filename, size_t _block_size);
/* Use this for reading multivolume files by filenames.
* NOTE: Must be NULL terminated. Sorting is NOT done. */
__LA_DECL int archive_read_open_filenames(struct archive *,
const char **_filenames, size_t _block_size);
__LA_DECL int archive_read_open_filename_w(struct archive *,
const wchar_t *_filename, size_t _block_size);
/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
__LA_DECL int archive_read_open_file(struct archive *,
const char *_filename, size_t _block_size);
const char *_filename, size_t _block_size) __LA_DEPRECATED;
/* Read an archive that's stored in memory. */
__LA_DECL int archive_read_open_memory(struct archive *,
void * buff, size_t size);
const void * buff, size_t size);
/* A more involved version that is only used for internal testing. */
__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff,
__LA_DECL int archive_read_open_memory2(struct archive *a, const void *buff,
size_t size, size_t read_size);
/* Read an archive that's already open, using the file descriptor. */
__LA_DECL int archive_read_open_fd(struct archive *, int _fd,
@@ -405,12 +561,41 @@ __LA_DECL int archive_read_next_header2(struct archive *,
* Retrieve the byte offset in UNCOMPRESSED data where last-read
* header started.
*/
__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *);
__LA_DECL la_int64_t archive_read_header_position(struct archive *);

/*
* Returns 1 if the archive contains at least one encrypted entry.
* If the archive format not support encryption at all
* ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned.
* If for any other reason (e.g. not enough data read so far)
* we cannot say whether there are encrypted entries, then
* ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned.
* In general, this function will return values below zero when the
* reader is uncertain or totally incapable of encryption support.
* When this function returns 0 you can be sure that the reader
* supports encryption detection but no encrypted entries have
* been found yet.
*
* NOTE: If the metadata/header of an archive is also encrypted, you
* cannot rely on the number of encrypted entries. That is why this
* function does not return the number of encrypted entries but#
* just shows that there are some.
*/
__LA_DECL int archive_read_has_encrypted_entries(struct archive *);

/*
* Returns a bitmask of capabilities that are supported by the archive format reader.
* If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned.
*/
__LA_DECL int archive_read_format_capabilities(struct archive *);

/* Read data from the body of an entry. Similar to read(2). */
__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *,
__LA_DECL la_ssize_t archive_read_data(struct archive *,
void *, size_t);

/* Seek within the body of an entry. Similar to lseek(2). */
__LA_DECL la_int64_t archive_seek_data(struct archive *, la_int64_t, int);

/*
* A zero-copy version of archive_read_data that also exposes the file offset
* of each returned block. Note that the client has no way to specify
@@ -418,7 +603,7 @@ __LA_DECL __LA_SSIZE_T archive_read_data(struct archive *,
* be strictly increasing and that returned blocks will not overlap.
*/
__LA_DECL int archive_read_data_block(struct archive *a,
const void **buff, size_t *size, __LA_INT64_T *offset);
const void **buff, size_t *size, la_int64_t *offset);

/*-
* Some convenience functions that are built on archive_read_data:
@@ -448,6 +633,14 @@ __LA_DECL int archive_read_set_option(struct archive *_a,
__LA_DECL int archive_read_set_options(struct archive *_a,
const char *opts);

/*
* Add a decryption passphrase.
*/
__LA_DECL int archive_read_add_passphrase(struct archive *, const char *);
__LA_DECL int archive_read_set_passphrase_callback(struct archive *,
void *client_data, archive_passphrase_callback *);


/*-
* Convenience function to recreate the current entry (whose header
* has just been read) on disk.
@@ -494,6 +687,18 @@ __LA_DECL int archive_read_set_options(struct archive *_a,
/* Default: Do not restore Mac extended metadata. */
/* This has no effect except on Mac OS. */
#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000)
/* Default: Use HFS+ compression if it was compressed. */
/* This has no effect except on Mac OS v10.6 or later. */
#define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000)
/* Default: Do not use HFS+ compression if it was not compressed. */
/* This has no effect except on Mac OS v10.6 or later. */
#define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000)
/* Default: Do not reject entries with absolute paths */
#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
/* Default: Do not clear no-change flags when unlinking object */
#define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000)
/* Default: Do not extract atomically (using rename) */
#define ARCHIVE_EXTRACT_SAFE_WRITES (0x40000)

__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
int flags);
@@ -505,7 +710,7 @@ __LA_DECL void archive_read_extract_set_progress_callback(struct archive *,
/* Record the dev/ino of a file that will not be written. This is
* generally set to the dev/ino of the archive being read. */
__LA_DECL void archive_read_extract_set_skip_file(struct archive *,
__LA_INT64_T, __LA_INT64_T);
la_int64_t, la_int64_t);

/* Close the file and release most resources. */
__LA_DECL int archive_read_close(struct archive *);
@@ -514,7 +719,7 @@ __LA_DECL int archive_read_close(struct archive *);
__LA_DECL int archive_read_free(struct archive *);
#if ARCHIVE_VERSION_NUMBER < 4000000
/* Synonym for archive_read_free() for backwards compatibility. */
__LA_DECL int archive_read_finish(struct archive *);
__LA_DECL int archive_read_finish(struct archive *) __LA_DEPRECATED;
#endif

/*-
@@ -544,31 +749,47 @@ __LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
/* The dev/ino of a file that won't be archived. This is used
* to avoid recursively adding an archive to itself. */
__LA_DECL int archive_write_set_skip_file(struct archive *,
__LA_INT64_T, __LA_INT64_T);
la_int64_t, la_int64_t);

#if ARCHIVE_VERSION_NUMBER < 4000000
__LA_DECL int archive_write_set_compression_bzip2(struct archive *);
__LA_DECL int archive_write_set_compression_compress(struct archive *);
__LA_DECL int archive_write_set_compression_gzip(struct archive *);
__LA_DECL int archive_write_set_compression_lzip(struct archive *);
__LA_DECL int archive_write_set_compression_lzma(struct archive *);
__LA_DECL int archive_write_set_compression_none(struct archive *);
__LA_DECL int archive_write_set_compression_bzip2(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_compress(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_gzip(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_lzip(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_lzma(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_none(struct archive *)
__LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_program(struct archive *,
const char *cmd);
__LA_DECL int archive_write_set_compression_xz(struct archive *);
const char *cmd) __LA_DEPRECATED;
__LA_DECL int archive_write_set_compression_xz(struct archive *)
__LA_DEPRECATED;
#endif

/* A convenience function to set the filter based on the code. */
__LA_DECL int archive_write_add_filter(struct archive *, int filter_code);
__LA_DECL int archive_write_add_filter_by_name(struct archive *,
const char *name);
__LA_DECL int archive_write_add_filter_b64encode(struct archive *);
__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
__LA_DECL int archive_write_add_filter_compress(struct archive *);
__LA_DECL int archive_write_add_filter_grzip(struct archive *);
__LA_DECL int archive_write_add_filter_gzip(struct archive *);
__LA_DECL int archive_write_add_filter_lrzip(struct archive *);
__LA_DECL int archive_write_add_filter_lz4(struct archive *);
__LA_DECL int archive_write_add_filter_lzip(struct archive *);
__LA_DECL int archive_write_add_filter_lzma(struct archive *);
__LA_DECL int archive_write_add_filter_lzop(struct archive *);
__LA_DECL int archive_write_add_filter_none(struct archive *);
__LA_DECL int archive_write_add_filter_program(struct archive *,
const char *cmd);
__LA_DECL int archive_write_add_filter_uuencode(struct archive *);
__LA_DECL int archive_write_add_filter_xz(struct archive *);
__LA_DECL int archive_write_add_filter_zstd(struct archive *);


/* A convenience function to set the format based on the code or name. */
@@ -580,27 +801,43 @@ __LA_DECL int archive_write_set_format_7zip(struct archive *);
__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
__LA_DECL int archive_write_set_format_cpio(struct archive *);
__LA_DECL int archive_write_set_format_cpio_bin(struct archive *);
__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
__LA_DECL int archive_write_set_format_cpio_odc(struct archive *);
__LA_DECL int archive_write_set_format_cpio_pwb(struct archive *);
__LA_DECL int archive_write_set_format_gnutar(struct archive *);
__LA_DECL int archive_write_set_format_iso9660(struct archive *);
__LA_DECL int archive_write_set_format_mtree(struct archive *);
__LA_DECL int archive_write_set_format_mtree_classic(struct archive *);
/* TODO: int archive_write_set_format_old_tar(struct archive *); */
__LA_DECL int archive_write_set_format_pax(struct archive *);
__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
__LA_DECL int archive_write_set_format_raw(struct archive *);
__LA_DECL int archive_write_set_format_shar(struct archive *);
__LA_DECL int archive_write_set_format_shar_dump(struct archive *);
__LA_DECL int archive_write_set_format_ustar(struct archive *);
__LA_DECL int archive_write_set_format_v7tar(struct archive *);
__LA_DECL int archive_write_set_format_warc(struct archive *);
__LA_DECL int archive_write_set_format_xar(struct archive *);
__LA_DECL int archive_write_set_format_zip(struct archive *);
__LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename);
__LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext);
__LA_DECL int archive_write_zip_set_compression_deflate(struct archive *);
__LA_DECL int archive_write_zip_set_compression_store(struct archive *);
/* Deprecated; use archive_write_open2 instead */
__LA_DECL int archive_write_open(struct archive *, void *,
archive_open_callback *, archive_write_callback *,
archive_close_callback *);
__LA_DECL int archive_write_open2(struct archive *, void *,
archive_open_callback *, archive_write_callback *,
archive_close_callback *, archive_free_callback *);
__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
__LA_DECL int archive_write_open_filename_w(struct archive *,
const wchar_t *_file);
/* A deprecated synonym for archive_write_open_filename() */
__LA_DECL int archive_write_open_file(struct archive *, const char *_file);
__LA_DECL int archive_write_open_file(struct archive *, const char *_file)
__LA_DEPRECATED;
__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
/* _buffSize is the size of the buffer, _used refers to a variable that
* will be updated after each write into the buffer. */
@@ -613,21 +850,25 @@ __LA_DECL int archive_write_open_memory(struct archive *,
*/
__LA_DECL int archive_write_header(struct archive *,
struct archive_entry *);
__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *,
__LA_DECL la_ssize_t archive_write_data(struct archive *,
const void *, size_t);

/* This interface is currently only available for archive_write_disk handles. */
__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *,
const void *, size_t, __LA_INT64_T);
__LA_DECL la_ssize_t archive_write_data_block(struct archive *,
const void *, size_t, la_int64_t);

__LA_DECL int archive_write_finish_entry(struct archive *);
__LA_DECL int archive_write_close(struct archive *);
/* Marks the archive as FATAL so that a subsequent free() operation
* won't try to close() cleanly. Provides a fast abort capability
* when the client discovers that things have gone wrong. */
__LA_DECL int archive_write_fail(struct archive *);
/* This can fail if the archive wasn't already closed, in which case
* archive_write_free() will implicitly call archive_write_close(). */
__LA_DECL int archive_write_free(struct archive *);
#if ARCHIVE_VERSION_NUMBER < 4000000
/* Synonym for archive_write_free() for backwards compatibility. */
__LA_DECL int archive_write_finish(struct archive *);
__LA_DECL int archive_write_finish(struct archive *) __LA_DEPRECATED;
#endif

/*
@@ -649,6 +890,13 @@ __LA_DECL int archive_write_set_option(struct archive *_a,
__LA_DECL int archive_write_set_options(struct archive *_a,
const char *opts);

/*
* Set a encryption passphrase.
*/
__LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p);
__LA_DECL int archive_write_set_passphrase_callback(struct archive *,
void *client_data, archive_passphrase_callback *);

/*-
* ARCHIVE_WRITE_DISK API
*
@@ -668,7 +916,7 @@ __LA_DECL int archive_write_set_options(struct archive *_a,
__LA_DECL struct archive *archive_write_disk_new(void);
/* This file will not be overwritten. */
__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
__LA_INT64_T, __LA_INT64_T);
la_int64_t, la_int64_t);
/* Set flags to control how the next item gets created.
* This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
__LA_DECL int archive_write_disk_set_options(struct archive *,
@@ -698,14 +946,14 @@ __LA_DECL int archive_write_disk_set_standard_lookup(struct archive *);
*/
__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
void * /* private_data */,
__LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
la_int64_t (*)(void *, const char *, la_int64_t),
void (* /* cleanup */)(void *));
__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
void * /* private_data */,
__LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
la_int64_t (*)(void *, const char *, la_int64_t),
void (* /* cleanup */)(void *));
__LA_DECL __LA_INT64_T archive_write_disk_gid(struct archive *, const char *, __LA_INT64_T);
__LA_DECL __LA_INT64_T archive_write_disk_uid(struct archive *, const char *, __LA_INT64_T);
__LA_DECL la_int64_t archive_write_disk_gid(struct archive *, const char *, la_int64_t);
__LA_DECL la_int64_t archive_write_disk_uid(struct archive *, const char *, la_int64_t);

/*
* ARCHIVE_READ_DISK API
@@ -726,19 +974,19 @@ __LA_DECL int archive_read_disk_entry_from_file(struct archive *,
struct archive_entry *, int /* fd */, const struct stat *);
/* Look up gname for gid or uname for uid. */
/* Default implementations are very, very stupid. */
__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_INT64_T);
__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_INT64_T);
__LA_DECL const char *archive_read_disk_gname(struct archive *, la_int64_t);
__LA_DECL const char *archive_read_disk_uname(struct archive *, la_int64_t);
/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
* results for performance. */
__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *);
/* You can install your own lookups if you like. */
__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *,
void * /* private_data */,
const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
const char *(* /* lookup_fn */)(void *, la_int64_t),
void (* /* cleanup_fn */)(void *));
__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *,
void * /* private_data */,
const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
const char *(* /* lookup_fn */)(void *, la_int64_t),
void (* /* cleanup_fn */)(void *));
/* Start traversal. */
__LA_DECL int archive_read_disk_open(struct archive *, const char *);
@@ -755,12 +1003,12 @@ __LA_DECL int archive_read_disk_can_descend(struct archive *);
__LA_DECL int archive_read_disk_current_filesystem(struct archive *);
__LA_DECL int archive_read_disk_current_filesystem_is_synthetic(struct archive *);
__LA_DECL int archive_read_disk_current_filesystem_is_remote(struct archive *);
/* Request that the access time of the entry visited by travesal be restored. */
/* Request that the access time of the entry visited by traversal be restored. */
__LA_DECL int archive_read_disk_set_atime_restored(struct archive *);
/*
* Set behavior. The "flags" argument selects optional behavior.
*/
/* Request that the access time of the entry visited by travesal be restored.
/* Request that the access time of the entry visited by traversal be restored.
* This is the same as archive_read_disk_set_atime_restored. */
#define ARCHIVE_READDISK_RESTORE_ATIME (0x0001)
/* Default: Do not skip an entry which has nodump flags. */
@@ -768,8 +1016,14 @@ __LA_DECL int archive_read_disk_set_atime_restored(struct archive *);
/* Default: Skip a mac resource fork file whose prefix is "._" because of
* using copyfile. */
#define ARCHIVE_READDISK_MAC_COPYFILE (0x0004)
/* Default: Do not traverse mount points. */
/* Default: Traverse mount points. */
#define ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS (0x0008)
/* Default: Xattrs are read from disk. */
#define ARCHIVE_READDISK_NO_XATTR (0x0010)
/* Default: ACLs are read from disk. */
#define ARCHIVE_READDISK_NO_ACL (0x0020)
/* Default: File flags are read from disk. */
#define ARCHIVE_READDISK_NO_FFLAGS (0x0040)

__LA_DECL int archive_read_disk_set_behavior(struct archive *,
int flags);
@@ -788,6 +1042,10 @@ __LA_DECL int archive_read_disk_set_metadata_filter_callback(struct archive *,
int (*_metadata_filter_func)(struct archive *, void *,
struct archive_entry *), void *_client_data);

/* Simplified cleanup interface;
* This calls archive_read_free() or archive_write_free() as needed. */
__LA_DECL int archive_free(struct archive *);

/*
* Accessor functions to read/set various information in
* the struct archive object:
@@ -798,7 +1056,7 @@ __LA_DECL int archive_read_disk_set_metadata_filter_callback(struct archive *,
* last filter, which is always the pseudo-filter that wraps the
* client callbacks. */
__LA_DECL int archive_filter_count(struct archive *);
__LA_DECL __LA_INT64_T archive_filter_bytes(struct archive *, int);
__LA_DECL la_int64_t archive_filter_bytes(struct archive *, int);
__LA_DECL int archive_filter_code(struct archive *, int);
__LA_DECL const char * archive_filter_name(struct archive *, int);

@@ -806,13 +1064,17 @@ __LA_DECL const char * archive_filter_name(struct archive *, int);
/* These don't properly handle multiple filters, so are deprecated and
* will eventually be removed. */
/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
__LA_DECL __LA_INT64_T archive_position_compressed(struct archive *);
__LA_DECL la_int64_t archive_position_compressed(struct archive *)
__LA_DEPRECATED;
/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
__LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *);
__LA_DECL la_int64_t archive_position_uncompressed(struct archive *)
__LA_DEPRECATED;
/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
__LA_DECL const char *archive_compression_name(struct archive *);
__LA_DECL const char *archive_compression_name(struct archive *)
__LA_DEPRECATED;
/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
__LA_DECL int archive_compression(struct archive *);
__LA_DECL int archive_compression(struct archive *)
__LA_DEPRECATED;
#endif

__LA_DECL int archive_errno(struct archive *);
@@ -846,6 +1108,8 @@ __LA_DECL int archive_match_excluded(struct archive *,
*/
__LA_DECL int archive_match_path_excluded(struct archive *,
struct archive_entry *);
/* Control recursive inclusion of directory content when directory is included. Default on. */
__LA_DECL int archive_match_set_inclusion_recursion(struct archive *, int);
/* Add exclusion pathname pattern. */
__LA_DECL int archive_match_exclude_pattern(struct archive *, const char *);
__LA_DECL int archive_match_exclude_pattern_w(struct archive *,
@@ -885,7 +1149,7 @@ __LA_DECL int archive_match_time_excluded(struct archive *,

/*
* Flags to tell a matching type of time stamps. These are used for
* following functinos.
* following functions.
*/
/* Time flag: mtime to be tested. */
#define ARCHIVE_MATCH_MTIME (0x0100)
@@ -905,7 +1169,7 @@ __LA_DECL int archive_match_include_date(struct archive *, int _flag,
const char *_datestr);
__LA_DECL int archive_match_include_date_w(struct archive *, int _flag,
const wchar_t *_datestr);
/* Set inclusion time by a particluar file. */
/* Set inclusion time by a particular file. */
__LA_DECL int archive_match_include_file_time(struct archive *,
int _flag, const char *_pathname);
__LA_DECL int archive_match_include_file_time_w(struct archive *,
@@ -921,8 +1185,8 @@ __LA_DECL int archive_match_exclude_entry(struct archive *,
__LA_DECL int archive_match_owner_excluded(struct archive *,
struct archive_entry *);
/* Add inclusion uid, gid, uname and gname. */
__LA_DECL int archive_match_include_uid(struct archive *, __LA_INT64_T);
__LA_DECL int archive_match_include_gid(struct archive *, __LA_INT64_T);
__LA_DECL int archive_match_include_uid(struct archive *, la_int64_t);
__LA_DECL int archive_match_include_gid(struct archive *, la_int64_t);
__LA_DECL int archive_match_include_uname(struct archive *, const char *);
__LA_DECL int archive_match_include_uname_w(struct archive *,
const wchar_t *);
@@ -930,6 +1194,10 @@ __LA_DECL int archive_match_include_gname(struct archive *, const char *);
__LA_DECL int archive_match_include_gname_w(struct archive *,
const wchar_t *);

/* Utility functions */
/* Convenience function to sort a NULL terminated list of strings */
__LA_DECL int archive_utility_string_sort(char **);

#ifdef __cplusplus
}
#endif
@@ -937,9 +1205,4 @@ __LA_DECL int archive_match_include_gname_w(struct archive *,
/* These are meaningless outside of this header. */
#undef __LA_DECL

/* These need to remain defined because they're used in the
* callback type definitions. XXX Fix this. This is ugly. XXX */
/* #undef __LA_INT64_T */
/* #undef __LA_SSIZE_T */

#endif /* !ARCHIVE_H_INCLUDED */

+ 146
- 40
libarchive/archive_entry.h View File

@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2003-2008 Tim Kientzle
* Copyright (c) 2016 Martin Matuska
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,7 +30,7 @@
#define ARCHIVE_ENTRY_H_INCLUDED

/* Note: Compiler will complain if this does not match archive.h! */
#define ARCHIVE_VERSION_NUMBER 3000004
#define ARCHIVE_VERSION_NUMBER 3005003

/*
* Note: archive_entry.h is for use outside of libarchive; the
@@ -41,6 +42,7 @@

#include <sys/types.h>
#include <stddef.h> /* for wchar_t */
#include <stdint.h>
#include <time.h>

#if defined(_WIN32) && !defined(__CYGWIN__)
@@ -48,14 +50,41 @@
#endif

/* Get a suitable 64-bit integer type. */
#if defined(_WIN32) && !defined(__CYGWIN__)
# define __LA_INT64_T __int64
#else
#if !defined(__LA_INT64_T_DEFINED)
# if ARCHIVE_VERSION_NUMBER < 4000000
#define __LA_INT64_T la_int64_t
# endif
#define __LA_INT64_T_DEFINED
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
typedef __int64 la_int64_t;
# else
#include <unistd.h>
# if defined(_SCO_DS)
# define __LA_INT64_T long long
# if defined(_SCO_DS) || defined(__osf__)
typedef long long la_int64_t;
# else
typedef int64_t la_int64_t;
# endif
# endif
#endif

/* The la_ssize_t should match the type used in 'struct stat' */
#if !defined(__LA_SSIZE_T_DEFINED)
/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
# if ARCHIVE_VERSION_NUMBER < 4000000
#define __LA_SSIZE_T la_ssize_t
# endif
#define __LA_SSIZE_T_DEFINED
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
typedef ssize_t la_ssize_t;
# elif defined(_WIN64)
typedef __int64 la_ssize_t;
# else
typedef long la_ssize_t;
# endif
# else
# define __LA_INT64_T int64_t
# include <unistd.h> /* ssize_t */
typedef ssize_t la_ssize_t;
# endif
#endif

@@ -63,12 +92,17 @@
#if ARCHIVE_VERSION_NUMBER >= 3999000
/* Switch to plain 'int' for libarchive 4.0. It's less broken than 'mode_t' */
# define __LA_MODE_T int
#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__)
#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
# define __LA_MODE_T unsigned short
#else
# define __LA_MODE_T mode_t
#endif

/* Large file support for Android */
#ifdef __ANDROID__
#include "android_lf.h"
#endif

/*
* On Windows, define LIBARCHIVE_STATIC if you're building or using a
* .lib. The default here assumes you're building a DLL. Only
@@ -93,6 +127,12 @@
# define __LA_DECL
#endif

#if defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 1
# define __LA_DEPRECATED __attribute__((deprecated))
#else
# define __LA_DEPRECATED
#endif

#ifdef __cplusplus
extern "C" {
#endif
@@ -150,6 +190,13 @@ struct archive_entry;
#define AE_IFDIR ((__LA_MODE_T)0040000)
#define AE_IFIFO ((__LA_MODE_T)0010000)

/*
* Symlink types
*/
#define AE_SYMLINK_TYPE_UNDEFINED 0
#define AE_SYMLINK_TYPE_FILE 1
#define AE_SYMLINK_TYPE_DIRECTORY 2

/*
* Basic object manipulation
*/
@@ -206,13 +253,15 @@ __LA_DECL void archive_entry_fflags(struct archive_entry *,
unsigned long * /* set */,
unsigned long * /* clear */);
__LA_DECL const char *archive_entry_fflags_text(struct archive_entry *);
__LA_DECL __LA_INT64_T archive_entry_gid(struct archive_entry *);
__LA_DECL la_int64_t archive_entry_gid(struct archive_entry *);
__LA_DECL const char *archive_entry_gname(struct archive_entry *);
__LA_DECL const char *archive_entry_gname_utf8(struct archive_entry *);
__LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *);
__LA_DECL const char *archive_entry_hardlink(struct archive_entry *);
__LA_DECL const char *archive_entry_hardlink_utf8(struct archive_entry *);
__LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *);
__LA_DECL __LA_INT64_T archive_entry_ino(struct archive_entry *);
__LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *);
__LA_DECL la_int64_t archive_entry_ino(struct archive_entry *);
__LA_DECL la_int64_t archive_entry_ino64(struct archive_entry *);
__LA_DECL int archive_entry_ino_is_set(struct archive_entry *);
__LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *);
__LA_DECL time_t archive_entry_mtime(struct archive_entry *);
@@ -220,6 +269,7 @@ __LA_DECL long archive_entry_mtime_nsec(struct archive_entry *);
__LA_DECL int archive_entry_mtime_is_set(struct archive_entry *);
__LA_DECL unsigned int archive_entry_nlink(struct archive_entry *);
__LA_DECL const char *archive_entry_pathname(struct archive_entry *);
__LA_DECL const char *archive_entry_pathname_utf8(struct archive_entry *);
__LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *);
__LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *);
__LA_DECL dev_t archive_entry_rdev(struct archive_entry *);
@@ -227,14 +277,20 @@ __LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *);
__LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *);
__LA_DECL const char *archive_entry_sourcepath(struct archive_entry *);
__LA_DECL const wchar_t *archive_entry_sourcepath_w(struct archive_entry *);
__LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *);
__LA_DECL la_int64_t archive_entry_size(struct archive_entry *);
__LA_DECL int archive_entry_size_is_set(struct archive_entry *);
__LA_DECL const char *archive_entry_strmode(struct archive_entry *);
__LA_DECL const char *archive_entry_symlink(struct archive_entry *);
__LA_DECL const char *archive_entry_symlink_utf8(struct archive_entry *);
__LA_DECL int archive_entry_symlink_type(struct archive_entry *);
__LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *);
__LA_DECL __LA_INT64_T archive_entry_uid(struct archive_entry *);
__LA_DECL la_int64_t archive_entry_uid(struct archive_entry *);
__LA_DECL const char *archive_entry_uname(struct archive_entry *);
__LA_DECL const char *archive_entry_uname_utf8(struct archive_entry *);
__LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *);
__LA_DECL int archive_entry_is_data_encrypted(struct archive_entry *);
__LA_DECL int archive_entry_is_metadata_encrypted(struct archive_entry *);
__LA_DECL int archive_entry_is_encrypted(struct archive_entry *);

/*
* Set fields in an archive_entry.
@@ -266,18 +322,21 @@ __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *,
const char *);
__LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
const wchar_t *);
__LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_INT64_T);
__LA_DECL void archive_entry_set_gid(struct archive_entry *, la_int64_t);
__LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_gname_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
__LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_hardlink_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
__LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_ino(struct archive_entry *, __LA_INT64_T);
__LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T);
__LA_DECL void archive_entry_set_ino(struct archive_entry *, la_int64_t);
__LA_DECL void archive_entry_set_ino64(struct archive_entry *, la_int64_t);
__LA_DECL void archive_entry_set_link(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_link_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
__LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *);
@@ -286,6 +345,7 @@ __LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long);
__LA_DECL void archive_entry_unset_mtime(struct archive_entry *);
__LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int);
__LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_pathname_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
__LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *);
@@ -293,19 +353,24 @@ __LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
__LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t);
__LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
__LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t);
__LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T);
__LA_DECL void archive_entry_set_size(struct archive_entry *, la_int64_t);
__LA_DECL void archive_entry_unset_size(struct archive_entry *);
__LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *);
__LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_symlink_type(struct archive_entry *, int);
__LA_DECL void archive_entry_set_symlink_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
__LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_INT64_T);
__LA_DECL void archive_entry_set_uid(struct archive_entry *, la_int64_t);
__LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_uname_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *);
__LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
__LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *);
__LA_DECL void archive_entry_set_is_data_encrypted(struct archive_entry *, char is_encrypted);
__LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, char is_encrypted);
/*
* Routines to bulk copy fields to/from a platform-native "struct
* stat." Libarchive used to just store a struct stat inside of each
@@ -331,6 +396,19 @@ __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat
__LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *);
__LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t);

/*
* Digest routine. This is used to query the raw hex digest for the
* given entry. The type of digest is provided as an argument.
*/
#define ARCHIVE_ENTRY_DIGEST_MD5 0x00000001
#define ARCHIVE_ENTRY_DIGEST_RMD160 0x00000002
#define ARCHIVE_ENTRY_DIGEST_SHA1 0x00000003
#define ARCHIVE_ENTRY_DIGEST_SHA256 0x00000004
#define ARCHIVE_ENTRY_DIGEST_SHA384 0x00000005
#define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006

__LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */);

/*
* ACL routines. This used to simply store and return text-format ACL
* strings, but that proved insufficient for a number of reasons:
@@ -393,6 +471,7 @@ __LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const voi
/*
* Inheritance values (NFS4 ACLs only); included in permset.
*/
#define ARCHIVE_ENTRY_ACL_ENTRY_INHERITED 0x01000000
#define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000
#define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000
#define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000
@@ -406,15 +485,16 @@ __LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const voi
| ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \
| ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \
| ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \
| ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS)
| ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS \
| ARCHIVE_ENTRY_ACL_ENTRY_INHERITED)

/* We need to be able to specify combinations of these. */
#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 /* POSIX.1e only */
#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 /* POSIX.1e only */
#define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 1024 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_DENY 2048 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 4096 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_ALARM 8192 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 0x00000100 /* POSIX.1e only */
#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 0x00000200 /* POSIX.1e only */
#define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 0x00000400 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_DENY 0x00000800 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 0x00001000 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_ALARM 0x00002000 /* NFS4 only */
#define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \
| ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)
#define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \
@@ -457,29 +537,56 @@ __LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type
__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */,
int * /* type */, int * /* permset */, int * /* tag */,
int * /* qual */, const char ** /* name */);
__LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */,
int * /* type */, int * /* permset */, int * /* tag */,
int * /* qual */, const wchar_t ** /* name */);

/*
* Construct a text-format ACL. The flags argument is a bitmask that
* can include any of the following:
*
* Flags only for archive entries with POSIX.1e ACL:
* ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries.
* ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries.
* ARCHIVE_ENTRY_ACL_TYPE_NFS4 - Include NFS4 entries.
* ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
* each ACL entry. ('star' introduced this for POSIX.1e, this flag
* also applies to NFS4.)
* ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
* default ACL entry, as used in old Solaris ACLs.
* default ACL entry.
* ARCHIVE_ENTRY_ACL_STYLE_SOLARIS - Output only one colon after "other" and
* "mask" entries.
*
* Flags only for archive entries with NFSv4 ACL:
* ARCHIVE_ENTRY_ACL_STYLE_COMPACT - Do not output the minus character for
* unset permissions and flags in NFSv4 ACL permission and flag fields
*
* Flags for for archive entries with POSIX.1e ACL or NFSv4 ACL:
* ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
* each ACL entry.
* ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA - Separate entries with comma
* instead of newline.
*/
#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 0x00000001
#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 0x00000002
#define ARCHIVE_ENTRY_ACL_STYLE_SOLARIS 0x00000004
#define ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA 0x00000008
#define ARCHIVE_ENTRY_ACL_STYLE_COMPACT 0x00000010

__LA_DECL wchar_t *archive_entry_acl_to_text_w(struct archive_entry *,
la_ssize_t * /* len */, int /* flags */);
__LA_DECL char *archive_entry_acl_to_text(struct archive_entry *,
la_ssize_t * /* len */, int /* flags */);
__LA_DECL int archive_entry_acl_from_text_w(struct archive_entry *,
const wchar_t * /* wtext */, int /* type */);
__LA_DECL int archive_entry_acl_from_text(struct archive_entry *,
const char * /* text */, int /* type */);

/* Deprecated constants */
#define OLD_ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
#define OLD_ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048

/* Deprecated functions */
__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *,
int /* flags */);
int /* flags */) __LA_DEPRECATED;
__LA_DECL const char *archive_entry_acl_text(struct archive_entry *,
int /* flags */);
int /* flags */) __LA_DEPRECATED;

/* Return bitmask of ACL types in an archive entry */
__LA_DECL int archive_entry_acl_types(struct archive_entry *);

/* Return a count of entries matching 'want_type' */
__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */);
@@ -514,7 +621,7 @@ __LA_DECL int archive_entry_xattr_next(struct archive_entry *,

__LA_DECL void archive_entry_sparse_clear(struct archive_entry *);
__LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *,
__LA_INT64_T /* offset */, __LA_INT64_T /* length */);
la_int64_t /* offset */, la_int64_t /* length */);

/*
* To retrieve the xattr list, first "reset", then repeatedly ask for the
@@ -524,7 +631,7 @@ __LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *,
__LA_DECL int archive_entry_sparse_count(struct archive_entry *);
__LA_DECL int archive_entry_sparse_reset(struct archive_entry *);
__LA_DECL int archive_entry_sparse_next(struct archive_entry *,
__LA_INT64_T * /* offset */, __LA_INT64_T * /* length */);
la_int64_t * /* offset */, la_int64_t * /* length */);

/*
* Utility to match up hardlinks.
@@ -604,7 +711,6 @@ __LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *,
struct archive_entry **, struct archive_entry **);
__LA_DECL struct archive_entry *archive_entry_partial_links(
struct archive_entry_linkresolver *res, unsigned int *links);

#ifdef __cplusplus
}
#endif


+ 18
- 17
libarchive/tar.py View File

@@ -1,13 +1,12 @@
import os
from libarchive import is_archive, Entry, SeekableArchive
from tarfile import DEFAULT_FORMAT, USTAR_FORMAT, GNU_FORMAT, PAX_FORMAT, \
ENCODING
from tarfile import DEFAULT_FORMAT, USTAR_FORMAT, GNU_FORMAT, PAX_FORMAT, ENCODING
from tarfile import REGTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CHRTYPE, BLKTYPE

FORMAT_CONVERSION = {
USTAR_FORMAT: 'tar',
GNU_FORMAT: 'gnu',
PAX_FORMAT: 'pax',
USTAR_FORMAT: 'tar',
GNU_FORMAT: 'gnu',
PAX_FORMAT: 'pax',
}


@@ -36,9 +35,13 @@ class TarInfo(Entry):
@property
def get_type(self):
for attr, type in (
('isdir', DIRTYPE), ('isfile', REGTYPE), ('issym', SYMTYPE),
('isfifo', FIFOTYPE), ('ischr', CHRTYPE), ('isblk', BLKTYPE),
):
('isdir', DIRTYPE),
('isfile', REGTYPE),
('issym', SYMTYPE),
('isfifo', FIFOTYPE),
('ischr', CHRTYPE),
('isblk', BLKTYPE),
):
if getattr(self, attr)():
return type

@@ -52,13 +55,12 @@ class TarInfo(Entry):


class TarFile(SeekableArchive):
getmember = SeekableArchive.getentry
list = SeekableArchive.printlist
extract = SeekableArchive.readpath
getmember = SeekableArchive.getentry
list = SeekableArchive.printlist
extract = SeekableArchive.readpath
extractfile = SeekableArchive.readstream

def __init__(self, name=None, mode='r', fileobj=None,
format=DEFAULT_FORMAT, tarinfo=TarInfo, encoding=ENCODING):
def __init__(self, name=None, mode='r', fileobj=None, format=DEFAULT_FORMAT, tarinfo=TarInfo, encoding=ENCODING):
if name:
f = name
elif fileobj:
@@ -67,8 +69,7 @@ class TarFile(SeekableArchive):
format = FORMAT_CONVERSION.get(format)
except KeyError:
raise Exception('Invalid tar format: %s' % format)
super(TarFile, self).__init__(f, mode=mode, format=format,
entry_class=tarinfo, encoding=encoding)
super(TarFile, self).__init__(f, mode=mode, format=format, entry_class=tarinfo, encoding=encoding)

def getmembers(self):
return list(self)
@@ -78,7 +79,7 @@ class TarFile(SeekableArchive):

def __next__(self):
raise NotImplementedError
pass # TODO: how to do this?
pass # TODO: how to do this?

def extract(self, member, path=None):
if path is None:
@@ -90,7 +91,7 @@ class TarFile(SeekableArchive):
return self.readpath(member, f)

def add(self, name, arcname, recursive=True, exclude=None, filter=None):
pass # TODO: implement this.
pass # TODO: implement this.

def addfile(self, tarinfo, fileobj):
return self.writepath(fileobj, tarinfo)


+ 32
- 18
libarchive/zip.py View File

@@ -1,10 +1,10 @@
import os, time
from libarchive import is_archive, Entry, SeekableArchive
from libarchive import is_archive, Entry, SeekableArchive, _libarchive
from zipfile import ZIP_STORED, ZIP_DEFLATED


def is_zipfile(filename):
return is_archive(filename, formats=('zip', ))
return is_archive(filename, formats=('zip',))


class ZipEntry(Entry):
@@ -60,41 +60,55 @@ class ZipEntry(Entry):
CRC = property(_get_missing, _set_missing)
compress_size = property(_get_missing, _set_missing)

# encryption is one of (traditional = zipcrypt, aes128, aes256)
class ZipFile(SeekableArchive):
def __init__(self, f, mode='r', compression=ZIP_DEFLATED, allowZip64=False):
super(ZipFile, self).__init__(f, mode=mode, format='zip', entry_class=ZipEntry, encoding='CP437')
if mode == 'w' and compression == ZIP_STORED:
# Disable compression for writing.
_libarchive.archive_write_set_format_option(self.archive._a, "zip", "compression", "store")
def __init__(self, f, mode='r', compression=ZIP_DEFLATED, allowZip64=False, password=None,
encryption=None):
self.compression = compression
self.encryption = encryption
super(ZipFile, self).__init__(
f, mode=mode, format='zip', entry_class=ZipEntry, encoding='CP437', password=password
)

getinfo = SeekableArchive.getentry
getinfo = SeekableArchive.getentry

def set_initial_options(self):
if self.mode == 'w' and self.compression == ZIP_STORED:
# Disable compression for writing.
_libarchive.archive_write_set_format_option(self._a, "zip", "compression", "store")
if self.mode == 'w' and self.password:
if not self.encryption:
self.encryption = "traditional"
_libarchive.archive_write_set_format_option(self._a, "zip", "encryption", self.encryption)

def namelist(self):
return list(self.iterpaths)
return list(self.iterpaths())

def infolist(self):
return list(self)

def open(self, name, mode, pwd=None):
if pwd:
raise NotImplemented('Encryption not supported.')
if mode == 'r':
if pwd:
self.add_passphrase(pwd)
return self.readstream(name)
else:
return self.writestream(name)

def extract(self, name, path=None, pwd=None):
if pwd:
raise NotImplemented('Encryption not supported.')
self.add_passphrase(pwd)
if not path:
path = os.getcwd()
return self.readpath(name, os.path.join(path, name))

def extractall(self, path, names=None, pwd=None):
if pwd:
raise NotImplemented('Encryption not supported.')
self.add_passphrase(pwd)
if not names:
names = self.namelist()
if names:
@@ -103,16 +117,16 @@ class ZipFile(SeekableArchive):

def read(self, name, pwd=None):
if pwd:
raise NotImplemented('Encryption not supported.')
return self.read(name)
self.add_passphrase(pwd)
return super(ZipFile, self).read(name)

def writestr(self, member, data, compress_type=None):
if compress_type != self.compression:
if compress_type != self.compression and not (compress_type is None):
raise Exception('Cannot change compression type for individual entries.')
return self.write(member, data)

def setpassword(self, pwd):
raise NotImplemented('Encryption not supported.')
return self.set_passphrase(pwd)

def testzip(self):
raise NotImplemented()


+ 55
- 47
setup.py View File

@@ -35,6 +35,18 @@ except ImportError:
from distutils.command.build_ext import build_ext
# Use a provided libarchive else default to hard-coded path.
libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
if libarchivePrefix:
includePath = libarchivePrefix + '/include'
else:
includePath = '/usr/local/include'
name = 'python-libarchive'
version = '4.0.1'
release = '1'
@@ -42,22 +54,19 @@ versrel = version + '-' + release
readme = 'README.rst'
download_url = "http://" + name + ".googlecode.com/files/" + name + "-" + \
versrel + ".tar.gz"
repourl = 'https://github.com/smartfile/python-libarchive'
long_description = open(readme).read()
class build_ext_extra(build_ext, object):
"""
Extend build_ext allowing extra_compile_args and extra_link_args to be set
on the command-line.
"""
user_options = build_ext.user_options
user_options.append(
('extra-compile-args=', None,
'Extra arguments passed directly to the compiler')
)
user_options.append(
('extra-link-args=', None,
'Extra arguments passed directly to the linker')
)
user_options.append(('extra-compile-args=', None, 'Extra arguments passed directly to the compiler'))
user_options.append(('extra-link-args=', None, 'Extra arguments passed directly to the linker'))
def initialize_options(self):
build_ext.initialize_options(self)
@@ -72,48 +81,47 @@ class build_ext_extra(build_ext, object):
super(build_ext_extra, self).build_extension(ext)
# Use a provided libarchive else default to hard-coded path.
libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
if libarchivePrefix:
extra_compile_args = ['-I{0}/include'.format(libarchivePrefix)]
extra_link_args = ['-Wl,-rpath={0}/lib'.format(libarchivePrefix)]
environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix,
environ.get('LDFLAGS', ''))
environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix, environ.get('LDFLAGS', ''))
else:
extra_compile_args = []
extra_link_args = ['-l:libarchive.so.13']
__libarchive = Extension(name='libarchive.__libarchive',
sources=['libarchive/_libarchive_wrap.c'],
libraries=['archive'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=['libarchive'],
)
setup(name = name,
version = versrel,
description = 'A libarchive wrapper for Python.',
long_description = long_description,
license = 'BSD-style license',
platforms = ['any'],
author = 'Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
author_email = 'tcunningham@smartfile.com',
url = 'https://github.com/smartfile/python-libarchive',
download_url = download_url,
packages = ['libarchive'],
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: System :: Archiving :: Compression',
'Topic :: Software Development :: Libraries :: Python Modules',
],
cmdclass = {
extra_link_args = ['-l:libarchive.so.18']
__libarchive = Extension(
name='libarchive.__libarchive',
sources=['libarchive/_libarchive.i'],
libraries=['archive'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=[includePath, 'libarchive'],
)
setup(
name=name,
version=versrel,
description='A libarchive wrapper for Python supporting password protection.',
long_description=long_description,
license='BSD-style license',
platforms=['any'],
author='Vadim Lebedev, Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
author_email='vadiml1024@gmail.com',
url=repourl,
download_url=download_url,
packages=['libarchive'],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: System :: Archiving :: Compression',
'Topic :: Software Development :: Libraries :: Python Modules',
],
cmdclass={
'build_ext': build_ext_extra,
},
ext_modules = [__libarchive],
)
},
ext_modules=[__libarchive],
)

+ 112
- 14
tests.py View File

@@ -80,8 +80,8 @@ class TestIsArchiveZip(unittest.TestCase):

def test_zip(self):
self.assertEqual(is_archive(ZIPPATH), True)
self.assertEqual(is_archive(ZIPPATH, formats=('zip', )), True)
self.assertEqual(is_archive(ZIPPATH, formats=('tar', )), False)
self.assertEqual(is_archive(ZIPPATH, formats=('zip',)), True)
self.assertEqual(is_archive(ZIPPATH, formats=('tar',)), False)


class TestIsArchiveTar(unittest.TestCase):
@@ -111,7 +111,7 @@ class TestZipRead(unittest.TestCase):
self.assertEqual(count, len(FILENAMES), 'Did not enumerate correct number of items in archive.')

def test_deferred_close_by_archive(self):
""" Test archive deferred close without a stream. """
"""Test archive deferred close without a stream."""
z = ZipFile(self.f, 'r')
self.assertIsNotNone(z._a)
self.assertIsNone(z._stream)
@@ -119,7 +119,7 @@ class TestZipRead(unittest.TestCase):
self.assertIsNone(z._a)

def test_deferred_close_by_stream(self):
""" Ensure archive closes self if stream is closed first. """
"""Ensure archive closes self if stream is closed first."""
z = ZipFile(self.f, 'r')
stream = z.readstream(FILENAMES[0])
stream.close()
@@ -131,8 +131,8 @@ class TestZipRead(unittest.TestCase):
self.assertTrue(stream.closed)

def test_close_stream_first(self):
""" Ensure that archive stays open after being closed if a stream is
open. Further, ensure closing the stream closes the archive. """
"""Ensure that archive stays open after being closed if a stream is
open. Further, ensure closing the stream closes the archive."""
z = ZipFile(self.f, 'r')
stream = z.readstream(FILENAMES[0])
z.close()
@@ -153,8 +153,8 @@ class TestZipRead(unittest.TestCase):
names.append(e.filename)
self.assertEqual(names, FILENAMES, 'File names differ in archive.')

#~ def test_non_ascii(self):
#~ pass
# ~ def test_non_ascii(self):
# ~ pass

def test_extract_str(self):
pass
@@ -175,8 +175,9 @@ class TestZipWrite(unittest.TestCase):
z.writepath(f)
z.close()


def test_writepath_directory(self):
""" Test writing a directory. """
"""Test writing a directory."""
z = ZipFile(self.f, 'w')
z.writepath(None, pathname='/testdir', folder=True)
z.writepath(None, pathname='/testdir/testinside', folder=True)
@@ -230,7 +231,7 @@ class TestZipWrite(unittest.TestCase):
z.close()

def test_deferred_close_by_archive(self):
""" Test archive deferred close without a stream. """
"""Test archive deferred close without a stream."""
z = ZipFile(self.f, 'w')
o = z.writestream(FILENAMES[0])
z.close()
@@ -246,12 +247,109 @@ class TestZipWrite(unittest.TestCase):
z.close()


import base64

# ZIP_CONTENT is base64 encoded password protected zip file with password: 'pwd' and following contents:
# unzip -l /tmp/zzz.zip
#Archive: /tmp/zzz.zip
# Length Date Time Name
#--------- ---------- ----- ----
# 9 08-09-2022 19:29 test.txt
#--------- -------
# 9 1 file

ZIP_CONTENT='UEsDBAoACQAAAKubCVVjZ7b1FQAAAAkAAAAIABwAdGVzdC50eHRVVAkAA5K18mKStfJid' + \
'XgLAAEEAAAAAAQAAAAA5ryoP1rrRK5apjO41YMAPjpkWdU3UEsHCGNntvUVAAAACQAAAF' + \
'BLAQIeAwoACQAAAKubCVVjZ7b1FQAAAAkAAAAIABgAAAAAAAEAAACkgQAAAAB0ZXN0LnR' + \
'4dFVUBQADkrXyYnV4CwABBAAAAAAEAAAAAFBLBQYAAAAAAQABAE4AAABnAAAAAAA='

ITEM_CONTENT='test.txt\n'
ITEM_NAME='test.txt'

ZIP1_PWD='pwd'
ZIP2_PWD='12345'
def create_file_from_content():
if PY3:
with open(ZIPPATH, mode='wb') as f:
f.write(base64.b64decode(ZIP_CONTENT))
else:
with open(ZIPPATH, mode='w') as f:
f.write(base64.b64decode(ZIP_CONTENT))


def create_protected_zip():
z = ZipFile(ZIPPATH, mode='w', password=ZIP2_PWD)
z.writestr(ITEM_NAME, ITEM_CONTENT)
z.close()


class TestProtectedReading(unittest.TestCase):
def setUp(self):
create_file_from_content()


def tearDown(self):
os.remove(ZIPPATH)

def test_read_with_password(self):
z = ZipFile(ZIPPATH, 'r', password=ZIP1_PWD)
if PY3:
self.assertEqual(z.read(ITEM_NAME), bytes(ITEM_CONTENT, 'utf-8'))
else:
self.assertEqual(z.read(ITEM_NAME), ITEM_CONTENT)
z.close()

def test_read_without_password(self):
z = ZipFile(ZIPPATH, 'r')
self.assertRaises(RuntimeError, z.read, ITEM_NAME)
z.close()

def test_read_with_wrong_password(self):
z = ZipFile(ZIPPATH, 'r', password='wrong')
self.assertRaises(RuntimeError, z.read, ITEM_NAME)
z.close()

class TestProtectedWriting(unittest.TestCase):
def setUp(self):
create_protected_zip()

def tearDown(self):
os.remove(ZIPPATH)

def test_read_with_password(self):
z = ZipFile(ZIPPATH, 'r', password=ZIP2_PWD)
if PY3:
self.assertEqual(z.read(ITEM_NAME), bytes(ITEM_CONTENT, 'utf-8'))
else:
self.assertEqual(z.read(ITEM_NAME), ITEM_CONTENT)
z.close()

def test_read_without_password(self):
z = ZipFile(ZIPPATH, 'r')
self.assertRaises(RuntimeError, z.read, ITEM_NAME)
z.close()

def test_read_with_wrong_password(self):
z = ZipFile(ZIPPATH, 'r', password='wrong')
self.assertRaises(RuntimeError, z.read, ITEM_NAME)
z.close()

def test_read_with_password_list(self):
z = ZipFile(ZIPPATH, 'r', password=[ZIP1_PWD, ZIP2_PWD])
if PY3:
self.assertEqual(z.read(ITEM_NAME), bytes(ITEM_CONTENT, 'utf-8'))
else:
self.assertEqual(z.read(ITEM_NAME), ITEM_CONTENT)
z.close()



class TestHighLevelAPI(unittest.TestCase):
def setUp(self):
make_temp_archive()

def _test_listing_content(self, f):
""" Test helper capturing file paths while iterating the archive. """
"""Test helper capturing file paths while iterating the archive."""
found = []
with Archive(f) as a:
for entry in a:
@@ -260,16 +358,16 @@ class TestHighLevelAPI(unittest.TestCase):
self.assertEqual(set(found), set(FILENAMES))

def test_open_by_name(self):
""" Test an archive opened directly by name. """
"""Test an archive opened directly by name."""
self._test_listing_content(ZIPPATH)

def test_open_by_named_fobj(self):
""" Test an archive using a file-like object opened by name. """
"""Test an archive using a file-like object opened by name."""
with open(ZIPPATH, 'rb') as f:
self._test_listing_content(f)

def test_open_by_unnamed_fobj(self):
""" Test an archive using file-like object opened by fileno(). """
"""Test an archive using file-like object opened by fileno()."""
with open(ZIPPATH, 'rb') as zf:
with io.FileIO(zf.fileno(), mode='r', closefd=False) as f:
self._test_listing_content(f)


Loading…
Cancel
Save