Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
Use dpkg-query rather than directly access dpkg database files.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.debian.org/cruft/trunk@210 14f89510-8efc-0310-927e-d869d0d96f2b
  • Loading branch information
porridge committed Mar 11, 2011
1 parent 8592370 commit bddad85
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 25 deletions.
10 changes: 6 additions & 4 deletions README
Expand Up @@ -85,9 +85,11 @@ the same name. So if you want to override /usr/lib/cruft/explain/foo, just
create an executable file called /etc/cruft/explain/foo.

Also, any explain script will be run only if any of the following is true:
- a package with the same name as the file is not completly purged (that
means, a .list, .postrm or .prerm file for this package exists in
/var/lib/dpkg/info)
- a package with the same name as the file is not completly purged - that is,
at least one of the following exist for the package:
* a non-empty file list,
* a postrm file,
* a prerm file.
- the name of the file contains no lower-case characters. Thus, the way to
have a script run regardless of any package being installed, just name it in
UPPER_CASE
Expand All @@ -101,7 +103,7 @@ following filter files will be selected:

- /etc/cruft/filters-TYPE/*
- /etc/cruft/filters/*
- /var/lib/dpkg/info/*.extrafiles
- installed "extrafiles" control files (in dpkg database)
- /usr/lib/cruft/filters-TYPE/*
- /usr/lib/cruft/filters/*

Expand Down
50 changes: 47 additions & 3 deletions common.sh
Expand Up @@ -163,12 +163,56 @@ fixup_slashes()
sed 's:/\.$:/:;s:/$::;s:^$:/:'
}

package_has_script()
{
local pkg="$1"
local script="$2"
local ctrl_path_tmp=$(mktemp)
if ! dpkg-query --control-path "${pkg}" "${script}" >"${ctrl_path_tmp}" 2>/dev/null
then
rm -f "${ctrl_path_tmp}"
# error, most likely ${pkg} is not installed
return 1
else
lines=$(wc -l < "${ctrl_path_tmp}")
rm -f "${ctrl_path_tmp}"
if [ "${lines}" -eq 0 ]
then
# no path returned
return 1
else
return 0
fi
fi
}

package_has_files()
{
local pkg="$1"
local list_tmp=$(mktemp)
if ! dpkg-query --listfiles "${pkg}" >"${list_tmp}" 2>/dev/null
then
rm -f "${list_tmp}"
# error, most likely ${pkg} is not installed
return 1
else
lines=$(wc -l < "${list_tmp}")
if [ "${lines}" -eq 0 ]
then
# has no files
return 1
else
return 0
fi
fi
}

package_installed()
{
local pkg="$1"
[ -f "/var/lib/dpkg/info/${pkg}.list" ] ||
[ -f "/var/lib/dpkg/info/${pkg}.prerm" ] ||
[ -f "/var/lib/dpkg/info/${pkg}.postrm" ]
package_has_script "${pkg}" prerm ||
package_has_script "${pkg}" postrm ||
package_has_files "${pkg}"
}

# return 0 if file with that name is to be processed
Expand Down
9 changes: 9 additions & 0 deletions debian/changelog
@@ -1,3 +1,12 @@
cruft (0.9.14) unstable; urgency=low

* Instead of directly accessing installed maintainer scripts and dpkg "list"
files, call dpkg-query as appropriate. This makes it much slower in some
cases but at least it will let us survive the incoming revolution in dpkg
database (closes: Bug#616068)

-- Marcin Owsiany <porridge@debian.org> Wed, 09 Mar 2011 09:21:40 +0000

cruft (0.9.13) experimental; urgency=high

* Changed all bash and sh scripts to use dash, because bash makes it hard to
Expand Down
4 changes: 1 addition & 3 deletions explain/apt-listchanges
@@ -1,6 +1,4 @@
#!/bin/dash
p='apt-listchanges'
f="/var/lib/dpkg/info/$p.list"
set -e
if [ ! -e "$f" ]; then exit 1; fi
cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
4 changes: 1 addition & 3 deletions explain/cvs2svn
@@ -1,6 +1,4 @@
#!/bin/dash
p='cvs2svn'
f="/var/lib/dpkg/info/$p.list"
set -e
if [ ! -e "$f" ]; then exit 1; fi
cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
4 changes: 1 addition & 3 deletions explain/linda
@@ -1,6 +1,4 @@
#!/bin/dash
p='linda'
f="/var/lib/dpkg/info/$p.list"
set -e
if [ ! -e "$f" ]; then exit 1; fi
cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
4 changes: 1 addition & 3 deletions explain/reportbug
@@ -1,6 +1,4 @@
#!/bin/dash
p='reportbug'
f="/var/lib/dpkg/info/$p.list"
set -e
if [ ! -e "$f" ]; then exit 1; fi
cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
4 changes: 1 addition & 3 deletions explain/rubber
@@ -1,6 +1,4 @@
#!/bin/dash
p='rubber'
f="/var/lib/dpkg/info/$p.list"
set -e
if [ ! -e "$f" ]; then exit 1; fi
cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done
6 changes: 3 additions & 3 deletions filters_list
Expand Up @@ -11,7 +11,7 @@ get_all_filter_basenames()
{
# the trick with cat is to detect "disk full" conditions but not fail on directory empty
(
if cd /var/lib/dpkg/info 2>/dev/null ; then ls *.extrafiles 2>/dev/null | sed 's,\.extrafiles$,,' ; fi
dpkg-query -W | awk '{print $1}' | xargs -I '{}' dpkg-query --control-path '{}' extrafiles | xargs -r -n 1 basename | sed 's,\.extrafiles$,,'
if cd /etc/cruft/filters 2>/dev/null ; then ls * 2>/dev/null | cat ; fi
if cd /usr/lib/cruft/filters 2>/dev/null ; then ls * 2>/dev/null | cat ; fi
if [ -n "${type}" ] ; then
Expand All @@ -27,8 +27,8 @@ for f in $(get_all_filter_basenames) ; do
echo "/etc/cruft/filters-${type}/${f}"
elif [ -e "/etc/cruft/filters/${f}" ] ; then
echo "${LIST}/etc/cruft/filters/${f}"
elif [ -e "/var/lib/dpkg/info/${f}.extrafiles" ] ; then
echo "${LIST}/var/lib/dpkg/info/${f}.extrafiles"
elif package_has_script "${f}" extrafiles ; then
dpkg-query --control-path "${f}" extrafiles | sed "s,^,${LIST},"
elif [ -n "${type}" -a -e "/usr/lib/cruft/filters-${type}/${f}" ] ; then
echo "${LIST}/usr/lib/cruft/filters-${type}/${f}"
elif [ -e "/usr/lib/cruft/filters/${f}" ] ; then
Expand Down

0 comments on commit bddad85

Please sign in to comment.