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

possible false positive in package_check #840

Merged
merged 3 commits into from
Mar 31, 2016

Conversation

keegoid
Copy link
Contributor

@keegoid keegoid commented Feb 29, 2016

Premise: It's better to check if a package doesn't exist, because a false positive here does no harm.

commit comment

use apt-cache policy instead of dpkg -s to check if pkg is NOT installed
sometimes dpkg -s will find Version information for packages that have
been removed, resulting in a false positive

reasoning

  1. If we check that a package exists and get a false positive, that package will never get installed.
  2. If we check that a package doesn't exist and get a false positive, apt-get will attempt to install it and notice that it is already installed.

example

remove virtualbox-5.0 and check if it still exists

sudo apt-get remove virtualbox-5.0
dpkg -s virtualbox-5.0 2>&1 | grep 'Version:'

This results in a false positive due to 'Version:' being found in several places.

Version: 5.0.14-105127~Ubuntu~trusty
Config-Version: 5.0.14-105127~Ubuntu~trusty
Python-Version: 2.7

check with apt-cache policy instead

apt-cache policy virtualbox-5.0

The result is not a false positive.

virtualbox-5.0:
  Installed: (none)
  Candidate: 5.0.14-105127~Ubuntu~trusty

use apt-cache policy instead of dpkg -s to check if pkg is NOT installed
sometimes dpkg -s will find Version information for packages that have
been removed, resulting in a false positive

 Changes to be committed:
	modified:   provision/provision.sh
@keegoid keegoid changed the title posible false positive in package_check possible false positive in package_check Feb 29, 2016
options should come before command as described in apt-get --help

 Changes to be committed:
	modified:   provision/provision.sh
if pkg is erroneously found by dpkg -s, apt-cache policy will correct it
if pkg is unrecognized, still attempt to install it

 Changes to be committed:
	modified:   provision/provision.sh
@keegoid
Copy link
Contributor Author

keegoid commented Mar 11, 2016

Perhaps a combination of the two will work better.

if [ "$(dpkg -s ${1} 2>&1 | grep 'Version:')" ]; then
   [ -n "$(apt-cache policy ${1} | grep 'Installed: (none)')" ] && return 0 || return 1
else
   return 0
fi

@jeremyfelt jeremyfelt added this to the Next Release milestone Mar 31, 2016
@jeremyfelt
Copy link
Member

Thanks for the excellent pull request, @keegoid. This makes sense.

@jeremyfelt jeremyfelt merged commit 0422404 into Varying-Vagrant-Vagrants:develop Mar 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants