I agree it is better to store the list of opportunities for each user
and remove the root differentiation, so how-can-i-help would behave
in the same way for any user and we can remove the "Not running as
root" help message.

Please review attached patch.

Note I considered using ruby-xdg for the folders creation but I could
not find it in debian.

I am not sure about how to manage the removal of the old DATADIR
(/var/lib/how-can-i-help) I suppose we can just leave
debian/how-can-i-help.postrm as it is.

Christophe
diff --git a/bin/how-can-i-help b/bin/how-can-i-help
index dcbbcff..54f1c72 100755
--- a/bin/how-can-i-help
+++ b/bin/how-can-i-help
@@ -23,17 +23,18 @@ require 'zlib'
 require 'stringio'
 require 'json'
 require 'optparse'
+require 'fileutils'
 
 HELPITEMS_URL = 'http://udd.debian.org/how-can-i-help.json.gz'
-DATADIR = '/var/lib/how-can-i-help'
-SEEN_LOCAL = "#{DATADIR}/seen.json"
-PACKAGES = "#{Dir.home}/.config/how-can-i-help/packages"
+CACHEDIR = "#{Dir.home}/.cache/how-can-i-help"
+CONFIGDIR = "#{Dir.home}/.config/how-can-i-help"
+SEEN_LOCAL = "#{CACHEDIR}/seen.json"
+PACKAGES = "#{CONFIGDIR}/packages"
 
 include Debian
 
 $quiet = false
 $all = false
-$root = (Process.euid == 0)
 
 optparse = OptionParser.new do |opts|
   opts.on('-h', '--help', 'show help') do
@@ -52,16 +53,13 @@ optparse = OptionParser.new do |opts|
 end
 optparse.parse!
 
-if not $root
-  puts "Not running as root, implies --all (lists all opportunities)..."
-  $all = true
-end
-
 def system_r(s)
   system(s) or raise
 end
 
-if $root and File::exists?(SEEN_LOCAL)
+FileUtils.mkdir_p CACHEDIR unless File.exists?(CACHEDIR)
+
+if File::exists?(SEEN_LOCAL)
   seen = JSON::parse(IO::read(SEEN_LOCAL))
 else
   seen = []
@@ -146,7 +144,7 @@ if not $all and not $quiet
   puts "------  Show all opportunities, not just new ones: how-can-i-help --all  ------"
 end
 
-if $root and not $all
+if not $all
   seen = helpitems.map { |hi| hi['hash'] } & seen
   seen = seen + helpitems_filtered.map { |hi| hi['hash'] }
   File::open(SEEN_LOCAL, 'w') do |fd|
diff --git a/debian/changelog b/debian/changelog
index 742c05b..01fb76a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+how-can-i-help (0.6+nmu3) UNRELEASED; urgency=low
+
+  * Non-maintainer upload.
+  * Remove non-root differentiation.
+
+ -- Christophe Siraut <[email protected]>  Tue, 01 Oct 2013 11:30:43 +0200
+
 how-can-i-help (0.6+nmu2) UNRELEASED; urgency=low
 
   * Non-maintainer upload.
diff --git a/debian/how-can-i-help.dirs b/debian/how-can-i-help.dirs
deleted file mode 100644
index 7270e4a..0000000
--- a/debian/how-can-i-help.dirs
+++ /dev/null
@@ -1 +0,0 @@
-var/lib/how-can-i-help

Reply via email to