[devscripts] 03/04: Store cached files in $XDG_CACHE_HOME

James McCoy jamessan at debian.org
Mon May 25 04:36:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch master
in repository devscripts.

commit f45a0b4b71424b50adffe4f8c47cca64ac5fff53
Author: James McCoy <jamessan at debian.org>
Date:   Sun May 24 23:14:50 2015 -0400

    Store cached files in $XDG_CACHE_HOME
    
    Change bts/rc-alert/wnpp-alert to store cached files under
    $XDG_CACHE_HOME/devscripts.  Include logic to migrate the existing cache
    to the new location on first use so things like “wnpp-alert -d” continue
    to work properly during the migration.
    
    Signed-off-by: James McCoy <jamessan at debian.org>
---
 debian/changelog      |  2 ++
 scripts/bts.pl        | 19 +++++++++++++++----
 scripts/rc-alert.1    |  4 ++--
 scripts/rc-alert.pl   | 22 ++++++++++++++++------
 scripts/wnpp-alert.1  |  2 +-
 scripts/wnpp-alert.sh | 14 ++++++++++++--
 6 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index fdb249a..68c141d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -23,6 +23,8 @@ devscripts (2.15.5) UNRELEASED; urgency=medium
     directory) to /usr/share/bash-completion/completions.
   * debdiff: Inspect wdiff's return code rather than Dpkg::IPC::spawn's
     exception to determine if wdiff found differences.  (Closes: #786518)
+  * Store cached files in $XDG_CACHE_HOME instead of ~/.devscripts_cache.
+    (Closes: #659330)
 
   [ Dominique Dumont ]
   * licensecheck:
diff --git a/scripts/bts.pl b/scripts/bts.pl
index 71695b9..43c8e6c 100755
--- a/scripts/bts.pl
+++ b/scripts/bts.pl
@@ -46,7 +46,7 @@ use 5.006_000;
 use strict;
 use File::Basename;
 use File::Copy;
-use File::Path;
+use File::Path qw(mkpath make_path rmtree);
 use File::Spec;
 use File::Temp qw/tempfile/;
 use Net::SMTP;
@@ -168,9 +168,11 @@ my @valid_severities=qw(wishlist minor normal important
 
 my $browser;  # Will set if necessary
 
-my $cachedir=$ENV{'HOME'}."/.devscripts_cache/bts/";
-my $timestampdb=$cachedir."bts_timestamps.db";
-my $prunestamp=$cachedir."bts_prune.timestamp";
+my $cachedir = $ENV{XDG_CACHE_HOME} || File::Spec->catdir($ENV{HOME}, '.cache');
+$cachedir = File::Spec->catdir($cachedir, 'devscripts', 'bts');
+
+my $timestampdb = File::Spec->catfile($cachedir, 'bts_timestamps.db');
+my $prunestamp = File::Spec->catfile($cachedir, 'bts_prune.timestamp');
 
 my %timestamp;
 END {
@@ -3684,6 +3686,15 @@ sub browse {
 # this at most once per day for efficiency.
 
 sub prunecache {
+    # TODO: Remove handling of $oldcache post-Stretch
+    my $oldcache = File::Spec->catdir($ENV{HOME}, '.devscripts_cache', 'bts');
+    if (-d $oldcache && ! -d $cachedir) {
+	my $err;
+	make_path(dirname($cachedir), { error => \$err });
+	if (!@$err) {
+	    system('mv', $oldcache, $cachedir);
+	}
+    }
     return unless -d $cachedir;
     return if -f $prunestamp and -M _ < 1;
 
diff --git a/scripts/rc-alert.1 b/scripts/rc-alert.1
index 840de79..8250aaa 100644
--- a/scripts/rc-alert.1
+++ b/scripts/rc-alert.1
@@ -10,14 +10,14 @@ rc-alert \- check for installed packages with release-critical bugs
 Debian BTS webpages, and then outputs a list of packages installed on
 the system, or given on the command-line, which are in that list.
 .P
-If the directory \fI~/.devscripts_cache\fP exists or the
+If the directory \fI$XDG_CACHE_HOME/devscripts/rc-alert\fP exists or the
 \fB\-\-cache\fP option is given, then the (sizable) downloaded list
 will be cached, and will only be downloaded again on a second
 invocation if it has changed.
 .SH OPTIONS
 .TP
 .BR \-\-cache
-Force the creation of the \fI~/.devscripts_cache\fP cache directory.
+Force the creation of the \fI$XDG_CACHE_HOME/devscripts/rc-alert\fP cache directory.
 .TP
 .BR \-\-help ", " \-h
 Show a summary of options.
diff --git a/scripts/rc-alert.pl b/scripts/rc-alert.pl
index 003bf46..9685c29 100755
--- a/scripts/rc-alert.pl
+++ b/scripts/rc-alert.pl
@@ -23,6 +23,9 @@ use strict;
 use warnings;
 use Devscripts::Packages;
 use File::Basename;
+use File::Copy qw(move);
+use File::Path qw(make_path);
+use File::Spec;
 use Getopt::Long qw(:config gnu_getopt);
 
 sub remove_duplicate_values($);
@@ -31,9 +34,11 @@ sub human_flags($);
 sub unhtmlsanit($);
 sub dt_parse_request($);
 
-my $cachedir = $ENV{'HOME'}."/.devscripts_cache/";
+my $cachedir = $ENV{XDG_CACHE_HOME} || File::Spec->catdir($ENV{HOME}, '.cache');
+$cachedir = File::Spec->catdir($cachedir, 'devscripts', 'rc-alert');
+
 my $url = "http://bugs.debian.org/release-critical/other/all.html";
-my $cachefile = $cachedir . basename($url);
+my $cachefile = File::Spec->catfile($cachedir, basename($url));
 my $forcecache = 0;
 my $usecache = 0;
 
@@ -171,10 +176,15 @@ if (system("command -v wget >/dev/null 2>&1") == 0) {
     die "$progname: this program requires either the wget or curl package to be installed\n";
 }
 
-
-if (! -d $cachedir and $forcecache) {
-    mkdir $cachedir
-	or die "$progname: can't make cache directory $cachedir: $!\n";
+# TODO: Remove oldcache handling post-Stretch
+my $oldcache = File::Spec->catfile($ENV{HOME}, '.devscripts_cache', 'all.html');
+if (! -d $cachedir) {
+    if (-f $oldcache || $forcecache) {
+	make_path($cachedir);
+	if (-f $oldcache) {
+	    move($oldcache, $cachefile);
+	}
+    }
 }
 
 if (-d $cachedir) {
diff --git a/scripts/wnpp-alert.1 b/scripts/wnpp-alert.1
index 3050c69..ce2a40f 100644
--- a/scripts/wnpp-alert.1
+++ b/scripts/wnpp-alert.1
@@ -17,7 +17,7 @@ package based.
 .SH OPTIONS
 .TP
 .BR \-\-diff ", " \-d
-If the \fI~/.devscripts_cache\fP directory exists, compare the output of
+If the \fI$XDG_CACHE_HOME/devscripts\fP directory exists, compare the output of
 \fBwnpp-alert\fR to the previous output (cached in the file
 \fIwnpp-diff\fR) and output the differences.
 .TP
diff --git a/scripts/wnpp-alert.sh b/scripts/wnpp-alert.sh
index bb20c37..4146d86 100755
--- a/scripts/wnpp-alert.sh
+++ b/scripts/wnpp-alert.sh
@@ -16,7 +16,11 @@
 set -e
 
 PROGNAME="${0##*/}"
-CACHEDIR=~/.devscripts_cache
+# TODO: Remove use of OLDCACHEDDIR post-Stretch
+OLDCACHEDIR=~/.devscripts_cache
+OLDCACHEDDIFF="${OLDCACHEDIR}/wnpp-diff"
+CACHEDIR=${XDG_CACHE_HOME:-$HOME/.cache}
+CACHEDIR=${CACHEDIR%/}/devscripts
 CACHEDDIFF="${CACHEDIR}/wnpp-diff"
 CURLORWGET=""
 GETCOMMAND=""
@@ -37,6 +41,9 @@ Modifications: Julian Gilbey <jdg at debian.org>"
 }
 
 wnppdiff () {
+    if [ -f "$OLDCACHEDDIFF" ]; then
+        mv "$OLDCACHEDDIFF" "$CACHEDDIFF"
+    fi
     if [ ! -f "$CACHEDDIFF" ]; then
         # First use
         comm -12 $WNPP_PACKAGES $INSTALLED | sed -e 's/+/\\+/g' | \
@@ -120,7 +127,10 @@ else
 fi
 
 if [ -f "$WNPP_DIFF" ]; then
-    if [ -d "$CACHEDIR" ]; then
+    # This may fail when run from a cronjob (c.f., #309802), so just ignore it
+    # and carry on.
+    mkdir -p "$CACHEDIR" >/dev/null 2>&1 || true
+    if [ -d "$CACHEDIR" ] || [ -d "$OLDCACHEDIR" ]; then
         wnppdiff
         exit 0
     else

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list