[Apt-listbugs-commits] [apt-listbugs] 01/02: store pins in preferences.d (Closes: #719988)
Francesco Poli
frx-guest at moszumanska.debian.org
Sat Aug 23 10:51:04 UTC 2014
This is an automated email from the git hooks/post-receive script.
frx-guest pushed a commit to branch master
in repository apt-listbugs.
commit 39efeeadadc353f4e9a8871bd5e3a6abdfa3bbfc
Author: Francesco Poli (wintermute) <invernomuto at paranoici.org>
Date: Sat Aug 23 12:45:01 2014 +0200
store pins in preferences.d (Closes: #719988)
---
Makefile | 4 ++-
aptcleanup | 26 +++++++++++------
debian/NEWS | 15 ++++++++++
debian/changelog | 4 +++
debian/cron.daily | 17 ++++++-----
debian/install | 1 +
debian/postinst | 32 +++++++++++++++++++++
lib/apt-listbugs/logic.rb | 7 +++--
lib/debian/apt_preferences.rb | 11 +++++--
migratepins | 67 +++++++++++++++++++++++++++++++++++++++++++
10 files changed, 163 insertions(+), 21 deletions(-)
diff --git a/Makefile b/Makefile
index b03874c..522fa15 100644
--- a/Makefile
+++ b/Makefile
@@ -29,13 +29,15 @@ update-po: po/apt-listbugs.pot
msgfmt --statistics -v -c po/$$po.po -o /dev/null; \
done
-po/apt-listbugs.pot: apt-listbugs lib/apt-listbugs/logic.rb aptcleanup
+po/apt-listbugs.pot: apt-listbugs lib/apt-listbugs/logic.rb aptcleanup \
+ migratepins
rxgettext --add-comments=TRANSLATORS --no-wrap \
--copyright-holder="Masato Taruishi et al." \
--copyright-year=2002-$(YEAR) \
--package-name=apt-listbugs --package-version=$(VERSION) \
--msgid-bugs-address=$$DEBEMAIL \
apt-listbugs lib/apt-listbugs/logic.rb aptcleanup \
+ migratepins \
-o po/apt-listbugs.pot
.PHONY: call-for-translation
diff --git a/aptcleanup b/aptcleanup
index ff07ef2..d71abac 100755
--- a/aptcleanup
+++ b/aptcleanup
@@ -36,13 +36,15 @@ include GetText
GetText::bindtextdomain("apt-listbugs")
require 'debian/apt_preferences'
-require 'tempfile'
+require 'tmpdir'
APTCACHE = "/usr/bin/apt-cache"
LISTBUGS = "/usr/sbin/apt-listbugs"
# read APT preferences
-pref_file = "/etc/apt/preferences"
+pref_dir = "/etc/apt/preferences.d"
+pref_name = "apt-listbugs"
+pref_file = pref_dir + "/" + pref_name
begin
p = Debian::AptPreferences.new
rescue Errno::ENOENT
@@ -58,11 +60,15 @@ end
pinned_pkg_keys = []
buggy_pkg_keys = []
-# store APT preferences with no apt-listbugs pins in a temporary file
-unpinned_pref_file = Tempfile.new('apt_preferences_')
+# store APT preferences with no apt-listbugs pins in a temporary directory
+unpinned_pref_dir = Dir.mktmpdir('apt_preferences_')
+
+begin
+
+FileUtils.cp_r "#{pref_dir}/.", unpinned_pref_dir
+unpinned_pref_file = File.open(unpinned_pref_dir + "/" + pref_name, "w")
p.filter( buggy_pkg_keys, unpinned_pref_file )
unpinned_pref_file.flush
-unpinned_preferences = unpinned_pref_file.path
p.pins.each do |pin|
if pin.listbugs?
@@ -71,7 +77,7 @@ p.pins.each do |pin|
# which version would get installed, if the pinning were removed ?
unpinned_candidate_version = nil
- policy_cand_line = `env LC_ALL=C #{APTCACHE} -o Dir::Etc::Preferences=#{unpinned_preferences} policy #{pinned_package} 2> /dev/null`.split("\n").select{|x| x.match("Candidate:")}[0]
+ policy_cand_line = `env LC_ALL=C #{APTCACHE} -o Dir::Etc::PreferencesParts=#{unpinned_pref_dir} policy #{pinned_package} 2> /dev/null`.split("\n").select{|x| x.match("Candidate:")}[0]
if policy_cand_line != nil
policy_cand_vers = policy_cand_line.split(" ")[1]
if policy_cand_vers != nil
@@ -105,8 +111,12 @@ p.pins.each do |pin|
end
end
-# get rid of the temporary file
-unpinned_pref_file.close!
+ensure
+
+# get rid of the temporary directory along with its content
+FileUtils.remove_entry unpinned_pref_dir
+
+end
$stderr.puts "Pinned packages: #{pinned_pkg_keys.sort.join(' ')}" if $DEBUG
$stderr.puts "Buggy packages : #{buggy_pkg_keys.sort.join(' ')}" if $DEBUG
diff --git a/debian/NEWS b/debian/NEWS
new file mode 100644
index 0000000..1cf60d0
--- /dev/null
+++ b/debian/NEWS
@@ -0,0 +1,15 @@
+apt-listbugs (0.1.14) unstable; urgency=medium
+
+ Starting from this version, apt-listbugs stores package pins in
+ /etc/apt/preferences.d/apt-listbugs, instead of /etc/apt/preferences ;
+ during the upgrade of apt-listbugs to a version >= 0.1.14, all your
+ apt-listbugs-managed pins are automatically migrated to the new
+ location.
+ In case you need to _downgrade_ apt-listbugs from a version >= 0.1.14
+ to a version <= 0.1.13, you may migrate all your apt-listbugs-managed
+ pins back to the old location by issuing the following commands:
+
+ # cat /etc/apt/preferences.d/apt-listbugs >> /etc/apt/preferences
+ # rm -f /etc/apt/preferences.d/apt-listbugs
+
+ -- Francesco Poli (wintermute) <invernomuto at paranoici.org> Tue, 22 Jul 2014 22:17:46 +0200
diff --git a/debian/changelog b/debian/changelog
index 98ebf01..24f1af3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -34,6 +34,10 @@ apt-listbugs (0.1.14) UNRELEASED; urgency=medium
bugs
* improved HTML bug lists (charset is now also declared in a meta http-equiv
statement, in order to enhance portability of the generated HTML page)
+ * fixed "Please support writing APT pinning to /etc/apt/preferences.d/":
+ package pins are now stored in /etc/apt/preferences.d/apt-listbugs;
+ see the NEWS file, in case you need to downgrade to a previous version
+ (Closes: #719988)
-- Francesco Poli (wintermute) <invernomuto at paranoici.org> Sun, 11 May 2014 16:45:18 +0200
diff --git a/debian/cron.daily b/debian/cron.daily
index 531d559..4661ad0 100755
--- a/debian/cron.daily
+++ b/debian/cron.daily
@@ -3,7 +3,7 @@
# Copyright (C) 2002-2004 Masato Taruishi <taru at debian.org>
# Copyright (C) 2006 Junichi Uekawa <dancer at debian.org>
# Copyright (C) 2007 Jean Lepropre <jlepropre at gmail.com>
-# Copyright (C) 2013 Francesco Poli <invernomuto at paranoici.org>
+# Copyright (C) 2013-2014 Francesco Poli <invernomuto at paranoici.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,21 +22,24 @@
prefclean()
{
+ file="/etc/apt/preferences.d/apt-listbugs"
+ backup="/var/backups/apt-listbugs.preferences"
+
test -x /usr/share/apt-listbugs/aptcleanup || return 0
test -x /usr/sbin/apt-listbugs || return 0
- test -f /etc/apt/preferences || return 0
+ test -f "$file" || return 0
tmp=$(mktemp --tmpdir apt-listbugs_tmp_preferences.XXXXXX)
/usr/share/apt-listbugs/aptcleanup > "$tmp" || return 0
- if ! diff -B "$tmp" /etc/apt/preferences > /dev/null
+ if ! diff -B "$tmp" "$file" > /dev/null
then
- if test -f "/var/backups/apt-listbugs.preferences"
+ if test -f "$backup"
then
- savelog -q /var/backups/apt-listbugs.preferences
+ savelog -q "$backup"
fi
- cp -aH /etc/apt/preferences /var/backups/apt-listbugs.preferences
- cp "$tmp" /etc/apt/preferences
+ cp -aH "$file" "$backup"
+ cp "$tmp" "$file"
fi
/bin/rm -f "$tmp"
}
diff --git a/debian/install b/debian/install
index 7c3eeca..81aef08 100644
--- a/debian/install
+++ b/debian/install
@@ -3,5 +3,6 @@ apt-listbugs usr/sbin/
ignore_bugs usr/share/apt-listbugs/
bug-list.css etc/apt/listbugs/
aptcleanup usr/share/apt-listbugs/
+migratepins usr/share/apt-listbugs/
lib/debian/*.rb usr/share/apt-listbugs/debian/
lib/apt-listbugs/*.rb usr/share/apt-listbugs/apt-listbugs/
diff --git a/debian/postinst b/debian/postinst
index 5c4d0bf..cbcc8a9 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -53,6 +53,38 @@ case "$1" in
fi
done
+ # migrate package pins to new location
+ MIGDIR=`/usr/share/apt-listbugs/migratepins`
+ if test "x$MIGDIR" != "x" && test -d "$MIGDIR"
+ then
+ if test -s "$MIGDIR/apt-listbugs"
+ then
+ echo -n "Migrating apt-listbugs pins to new location (see NEWS file) ... "
+ # append the migrated pins to the new location
+ DEST="/etc/apt/preferences.d/apt-listbugs"
+ echo "" >> "$DEST"
+ cat "$MIGDIR/apt-listbugs" >> "$DEST"
+ # backup the old file
+ DEST="/etc/apt/preferences"
+ BACKUP="/var/backups/apt-listbugs.pre-migration-preferences"
+ if test -f "$BACKUP"
+ then
+ savelog -q "$BACKUP"
+ fi
+ cp -aH "$DEST" "$BACKUP"
+ # replace the old file with the remaining pins
+ if test -s "$MIGDIR/preferences"
+ then
+ cp "$MIGDIR/preferences" "$DEST"
+ else
+ rm -f "$DEST"
+ fi
+ echo "done"
+ fi
+ rm -f "$MIGDIR/preferences" "$MIGDIR/apt-listbugs"
+ rmdir --ignore-fail-on-non-empty "$MIGDIR"
+ fi
+
;;
abort-upgrade|abort-remove|abort-deconfigure)
diff --git a/lib/apt-listbugs/logic.rb b/lib/apt-listbugs/logic.rb
index aea30d2..9b29d5c 100644
--- a/lib/apt-listbugs/logic.rb
+++ b/lib/apt-listbugs/logic.rb
@@ -605,11 +605,14 @@ class Viewer
}
$stderr.puts holdstr if $DEBUG
if holdstr != ""
- filename = "/etc/apt/preferences"
+ filename = "/etc/apt/preferences.d/apt-listbugs"
begin
File.open(filename, "a") { |io|
io.puts holdstr
- @config.frontend.puts sprintf(_("%s pinned by adding Pin preferences in /etc/apt/preferences. Restart APT session to enable"), pkg_keys.join(' '))
+ # TRANSLATORS: %{packgl} is a list of packages, %{filenm} is a file name.
+ @config.frontend.puts _("%{packgl} pinned by adding Pin preferences in %{filenm}. Restart APT session to enable") %
+ {:packgl => pkg_keys.join(' '),
+ :filenm => filename}
return pkg_keys
}
rescue Errno::EACCES
diff --git a/lib/debian/apt_preferences.rb b/lib/debian/apt_preferences.rb
index dca6281..aa6795f 100644
--- a/lib/debian/apt_preferences.rb
+++ b/lib/debian/apt_preferences.rb
@@ -1,7 +1,7 @@
#
# apt_preferences.rb - ruby interface for APT preferences
# Copyright (C) 2004 Masato Taruishi <taru at debian.org>
-# Copyright (C) 2009-2013 Francesco Poli <invernomuto at paranoici.org>
+# Copyright (C) 2009-2014 Francesco Poli <invernomuto at paranoici.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -46,7 +46,7 @@ module Debian
end
- def initialize( file = "/etc/apt/preferences" )
+ def initialize( file = "/etc/apt/preferences.d/apt-listbugs" )
@pins = []
open(file) { |io|
@pref = io.read
@@ -74,12 +74,17 @@ module Debian
attr_reader :pins
- def filter( pkg_keys = [], out = $stdout )
+ def filter( pkg_keys = [], out = $stdout, remainder = nil )
_each_pin do |pin|
p = Pin.new(pin)
if ! p.listbugs? || pkg_keys.include?( p["Package"] )
out.puts pin
out.puts ""
+ else
+ if remainder != nil
+ remainder.puts pin
+ remainder.puts ""
+ end
end
end
end
diff --git a/migratepins b/migratepins
new file mode 100755
index 0000000..83dd9b9
--- /dev/null
+++ b/migratepins
@@ -0,0 +1,67 @@
+#!/usr/bin/ruby
+#
+# migratepins: migrates all apt-listbugs-managed pins from
+# /etc/apt/preferences to <tmpdir>/apt-listbugs
+# and everything else to <tmpdir>/preferences
+#
+# Copyright (C) 2009 Ryan Niebur <ryan at debian.org>
+# Copyright (C) 2014 Francesco Poli <invernomuto at paranoici.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License with
+# the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL-2;
+# if not, write to the Free Software Foundation, Inc., 51 Franklin St,
+# Fifth Floor, Boston, MA 02110-1301, USA.
+#
+#
+
+if File.expand_path(__FILE__).match(/^\/usr\/share\/apt-listbugs\//)
+ $LOAD_PATH.unshift("/usr/share/apt-listbugs")
+else
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
+end
+
+require 'gettext'
+include GetText
+
+GetText::bindtextdomain("apt-listbugs")
+
+require 'debian/apt_preferences'
+require 'tmpdir'
+
+# create a temporary directory to split APT preferences
+# and print its name to stdout
+dest_dir = Dir.mktmpdir('pin_migration_')
+puts dest_dir
+
+# read APT preferences from /etc/apt/preferences
+pref_file = "/etc/apt/preferences"
+begin
+ p = Debian::AptPreferences.new(pref_file)
+rescue Errno::ENOENT
+ $stderr.puts sprintf("Cannot find %s: exiting!", pref_file) if $DEBUG
+ exit 0
+rescue Errno::EACCES
+ $stderr.puts _("E: ") + sprintf(_("Cannot read from %s"), pref_file)
+ exit 1
+rescue
+ $stderr.puts _("E: ") + "#{$!}"
+ exit 1
+end
+
+# split APT preferences:
+# all apt-listbugs-managed pins go to dest_dir/apt-listbugs
+# everything else goes to dest_dir/preferences
+new_pref_file = File.open(dest_dir + "/preferences", "w")
+new_aptl_file = File.open(dest_dir + "/apt-listbugs", "w")
+p.filter( [], new_pref_file, new_aptl_file )
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/apt-listbugs/apt-listbugs.git
More information about the Apt-listbugs-commits
mailing list