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

Backport to 1.x: Fix FD leakage by closing apt cache in repo.py #291

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 16 additions & 12 deletions snapcraft/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,24 @@ def _check_call(args, **kwargs):


def _install_build_packages(packages):
unique_packages = set(packages)
new_packages = []
for pkg in packages:
try:
if not apt.Cache()[pkg].installed:
new_packages.append(pkg)
except KeyError:
logger.error('Could not find all the "build-packages" required '
'in snapcraft.yaml')
sys.exit(1)
with apt.Cache() as apt_cache:
for pkg in unique_packages:
try:
if not apt_cache[pkg].installed:
new_packages.append(pkg)
except KeyError:
logger.error('Could not find all the "build-packages" '
'required in snapcraft.yaml')
sys.exit(1)
if new_packages:
logger.info('Installing required packages on the host system')
_check_call(['sudo', 'apt-get', '-o', 'Dpkg::Progress-Fancy=1',
'--no-install-recommends',
'-y', 'install'] + new_packages)
logger.info(
'Installing build dependencies: %s', ' '.join(new_packages))
subprocess.check_call(['sudo', 'apt-get', '-o',
'Dpkg::Progress-Fancy=1',
'--no-install-recommends',
'-y', 'install'] + new_packages)


def _load_config():
Expand Down