[Apt-listbugs-commits] [apt-listbugs] 02/02: warn if /etc/apt/preferences cannot be written to

Francesco Poli frx-guest at moszumanska.debian.org
Sat Jun 21 16:56:21 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 159bea526c6e1f305139250e42c516b3d2448c25
Author: Francesco Poli (wintermute) <invernomuto at paranoici.org>
Date:   Sat Jun 21 18:54:47 2014 +0200

    warn if /etc/apt/preferences cannot be written to
---
 debian/changelog          |  2 ++
 lib/apt-listbugs/logic.rb | 17 ++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index a3163ff..8539aff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -15,6 +15,8 @@ apt-listbugs (0.1.14) UNRELEASED; urgency=medium
     there are a lot of them.": it is now possible to make apt-listbugs
     exit immediately (and successfully) by sending it a SIGUSR1, for
     instance with the command "killall -USR1 apt-listbugs" (Closes: #273565)
+  * added a warning about pinning: when /etc/apt/preferences cannot be
+    written to, apt-listbugs warns the user, rather than crashing
 
  -- Francesco Poli (wintermute) <invernomuto at paranoici.org>  Sun, 11 May 2014 16:45:18 +0200
 
diff --git a/lib/apt-listbugs/logic.rb b/lib/apt-listbugs/logic.rb
index dfd76f7..df7085c 100644
--- a/lib/apt-listbugs/logic.rb
+++ b/lib/apt-listbugs/logic.rb
@@ -563,11 +563,18 @@ class Viewer
       }
       $stderr.puts holdstr if $DEBUG
       if holdstr != ""
-        File.open("/etc/apt/preferences", "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(' '))
-          return pkg_keys
-        }
+        filename = "/etc/apt/preferences"
+        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(' '))
+            return pkg_keys
+          }
+        rescue Errno::EACCES
+          # write-access is not possible, warn the user that the
+          # file won't be updated
+          $stderr.puts _("W: ") + sprintf(_("Cannot write to %s"), filename)
+        end
       end
       return nil
     end

-- 
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