Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix ctypes.util.find_library usage #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions libarchive/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

_LOGGER = logging.getLogger(__name__)

_LIBRARY_NAME = 'libarchive'
_LIBRARY_NAME = 'archive'
_LIBRARY_FILENAME = 'libarchive.so'

def find_and_load_library():
Expand All @@ -26,20 +26,19 @@ def find_and_load_library():
filepath = os.path.join(path, _LIBRARY_FILENAME)
search_filepaths.append(filepath)

# Search for our library using whatever search-path ctypes uses (not the same
# as `LD_LIBRARY_PATH`).

filepath = ctypes.util.find_library(_LIBRARY_NAME)
if filepath is not None:
search_filepaths.append(filepath)

# Load the first one available.

found_filepath = None
for filepath in search_filepaths:
if os.path.exists(filepath) is True:
return filepath

# Search for our library using whatever search-path ctypes uses (not the same
# as `LD_LIBRARY_PATH`).
filepath = ctypes.util.find_library(_LIBRARY_NAME)
if filepath is not None:
return filepath

# Fallback on the naively trying to load the filename.

_LOGGER.debug("Using default library file-path: [%s]", _LIBRARY_FILENAME)
Expand Down
6 changes: 0 additions & 6 deletions libarchive/resources/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ PyPI::
Notes
-----

- The Ubuntu `libarchive` package maintainer only provides a "libarchive.so" symlink in the dev package so you'll have to install the `libarchive-dev` package.

For example::

apt-get install libarchive-dev

- Encryption is not currently supported since it's not supported in the underlying library (*libarchive*). Note `this inquiry <https://github.com/libarchive/libarchive/issues/579>`_ and the `wishlist item <https://github.com/libarchive/libarchive/wiki/WishList#encrypted-backup-support>`_.

- OS X has a system version of `libarchive` that is very old. As a result, many users have encountered issues importing an alternate one. Specifically, often they install a different one via Brew but this will not be [sym]linked into the system like other packages. This is a precaution taken by Brew to prevent undefined behavior in the parts of OS X that depend on the factory version. In order to work around this, you should set `LD_LIBRARY_PATH` (or prepend if `LD_LIBRARY_PATH` is already defined) with the path of the location of the library version you want to use. You'll want to set this from your user-profile script (unless your environment can not support this and you need to prepend something like "LD_LIBRARY_PATH=/some/path" to the front of the command-line or set it via `os.environ` above where you import this package). A `tool <tools/brew_find_libarchive>`_ has been provided that will print the path of the first version of `libarchive` installed via Brew. Just copy-and-paste it. Thanks to @SkyLeach for discussing the issue and treatments.
Expand Down