From bdd93ef38f6ca3cade06a9b4ae7f657ef77ce297 Mon Sep 17 00:00:00 2001
From: blundellc <blundellc@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Date: Sat, 13 Sep 2008 13:21:11 +0000
Subject: [PATCH] cran2deb: use /var/cache/cran2deb as a permanent cache
 between installs.

Previously, when a new cran2deb was installed, cran2deb update would
re-generate the database and cache in their entirety, as well as lose
all previously generated .debs.  Instead they are stored outside the R
package heirarchy and so persist.

The cache is intended to contain everything that should be kept
in-memory for cran2deb (e.g., common data structures like the list of
all available packages), whilst the database is for all other data to be
stored on disk.

git-svn-id: svn://svn.r-forge.r-project.org/svnroot/cran2deb@81 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
---
 pkg/trunk/R/db.R                 |  2 +-
 pkg/trunk/R/zzz.R                | 15 ++++++++-------
 pkg/trunk/exec/diagnose          | 21 ++++++++++-----------
 pkg/trunk/exec/update            | 20 +++++++++++---------
 pkg/trunk/exec/update_cache      |  2 +-
 pkg/trunk/inst/doc/README        |  8 +++++---
 pkg/trunk/inst/etc/pbuilderrc.in |  2 +-
 7 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/pkg/trunk/R/db.R b/pkg/trunk/R/db.R
index c802bae..81b7b59 100644
--- a/pkg/trunk/R/db.R
+++ b/pkg/trunk/R/db.R
@@ -1,7 +1,7 @@
 
 db_start <- function() {
     drv <- dbDriver('SQLite')
-    con <- dbConnect(drv, dbname=file.path(root,'data/cran2deb.db'))
+    con <- dbConnect(drv, dbname=file.path(cache_root,'cran2deb.db'))
     tables <- dbListTables(con)
     if (!dbExistsTable(con,'sysreq_override')) {
         dbGetQuery(con,paste('CREATE TABLE sysreq_override ('
diff --git a/pkg/trunk/R/zzz.R b/pkg/trunk/R/zzz.R
index be2d55e..7a53227 100644
--- a/pkg/trunk/R/zzz.R
+++ b/pkg/trunk/R/zzz.R
@@ -1,20 +1,21 @@
 .First.lib <- function(libname, pkgname) {
     global <- function(name,value) assign(name,value,envir=.GlobalEnv)
-    global("changesfile", function(srcname,version='*') {
-        return(file.path(pbuilder_results
-                        ,paste(srcname,'_',version,'_'
-                              ,host_arch(),'.changes',sep='')))
-    })
     global("maintainer", 'cran2deb buildbot <cran2deb@example.org>')
     global("root", system.file(package='cran2deb'))
-    global("pbuilder_results", file.path(root,'var/results'))
+    global("cache_root", '/var/cache/cran2deb')
+    global("pbuilder_results", '/var/cache/cran2deb/results')
     global("pbuilder_config", file.path(root,'etc/pbuilderrc'))
     global("dput_config", file.path(root,'etc/dput.cf'))
     global("dinstall_config", file.path(root,'etc/mini-dinstall.conf'))
     global("dinstall_archive", file.path(root,'var/archive'))
     global("r_depend_fields", c('Depends','Imports')) # Suggests, Enhances
+    global("changesfile", function(srcname,version='*') {
+        return(file.path(pbuilder_results
+                        ,paste(srcname,'_',version,'_'
+                              ,host_arch(),'.changes',sep='')))
+    })
 
-    cache <- file.path(root,'data/cache.rda')
+    cache <- file.path(cache_root,'cache.rda')
     if (file.exists(cache)) {
         load(cache,envir=.GlobalEnv)
     }
diff --git a/pkg/trunk/exec/diagnose b/pkg/trunk/exec/diagnose
index 5f303e7..091da01 100755
--- a/pkg/trunk/exec/diagnose
+++ b/pkg/trunk/exec/diagnose
@@ -1,9 +1,8 @@
 #!/usr/bin/rc
 
-#success=`{ls var/results/*.deb | wc -l}
-#echo $success successful packages
-#total=$success
-total=0
+success=`{ls /var/cache/cran2deb/results/*.deb | wc -l}
+echo $success successful packages
+total=$success
 
 fn count_dup { sort | uniq -c | sort -n}# | awk '$1 > 1{print}' }
 fn collapse { a=`{echo $^* | sed -e 's/ | /|/g'}; echo $^a }
@@ -15,7 +14,7 @@ faildep=('^Error: package ''.*'' could not be loaded'
      '|' '^ERROR: lazy loading failed for package ''.*'''
      '|' '^[[:space:]]*package .* is not available'
      '|' 'there is no package called ''.*''')
-faildeb='Unsupported SystemRequirements:'
+faildeb='do not know what to do with SystemRequirement:'
 faillic=('No acceptable license: ')
 failspc=': No space left on device'
 failhdr='error: .*\.hp?p?: No such file or directory'
@@ -62,11 +61,11 @@ echo
 nfailother=`{hoc -e `{grep -EL $other fail/* /dev/null | wc -l}^-1}
 echo $nfailother other failures.
 
-#total=`{hoc -e $total}
-#succrate=`{hoc -e $success/'('$total')*100'}
-#echo $succrate% success rate '('$total' total)'
-#total=`{hoc -e $total-$nfaillic-$nfailspc-$nfailhdr}
-#succrate=`{hoc -e $success/'('$total')*100'}
-#echo $succrate% success rate without licensing, space and Debian deps issues '('$total' total)'
+total=`{hoc -e $total}
+succrate=`{hoc -e $success/'('$total')*100'}
+echo $succrate% success rate '('$total' total)'
+total=`{hoc -e $total-$nfaillic-$nfailspc-$nfailhdr}
+succrate=`{hoc -e $success/'('$total')*100'}
+echo $succrate% success rate without licensing, space and Debian deps issues '('$total' total)'
 grep -EL $other fail/* /dev/null | xargs tail -n 20
 
diff --git a/pkg/trunk/exec/update b/pkg/trunk/exec/update
index e816a20..7659205 100755
--- a/pkg/trunk/exec/update
+++ b/pkg/trunk/exec/update
@@ -6,17 +6,19 @@ for (x in `{find $root/etc -type f -name '*.in'}) {
     y=`{echo $x | sed -e 's,.in$,,'}
     sed -e 's:@ROOT@:'^$root^':g' <$x >$y
 }
-mkdir -p $root/var/results
+mkdir -p /var/cache/cran2deb/results || exit 1
 if ([ ! -e $root/var/archive ]) {
     # I symbolically link this into /var/www/
-    mkdir $root/var/archive
+    mkdir $root/var/archive || exit 1
 }
 mini-dinstall --batch -c $root/etc/mini-dinstall.conf || exit 1
-mode=create
-if ([ -e /var/cache/pbuilder/base-cran2deb.tgz ]) {
-    mode=update
+if (! ~ $1 quick) {
+    mode=create
+    if ([ -e /var/cache/pbuilder/base-cran2deb.tgz ]) {
+        mode=update
+    }
+    sudo pbuilder $mode --override-config --configfile $root/etc/pbuilderrc
+    $root/exec/update_cache $root
+    $root/exec/license <$root/data/populate_licenses
+    $root/exec/sysreq <$root/data/populate_sysreq
 }
-sudo pbuilder $mode --override-config --configfile $root/etc/pbuilderrc
-$root/exec/update_cache $root
-$root/exec/license <$root/data/populate_licenses
-$root/exec/sysreq <$root/data/populate_sysreq
diff --git a/pkg/trunk/exec/update_cache b/pkg/trunk/exec/update_cache
index ef91f13..60c63c0 100755
--- a/pkg/trunk/exec/update_cache
+++ b/pkg/trunk/exec/update_cache
@@ -24,4 +24,4 @@ base_pkgs <- readLines(pipe(paste('sudo pbuilder --execute --override-config --c
 message('updating list of existing Debian packages...')
 debian_pkgs <- readLines(pipe('apt-cache rdepends r-base-core | sed -e "/^  r-cran/{s/^[[:space:]]*r/r/;p}" -e d | sort -u'))
 
-save(debian_pkgs, base_pkgs, available, ctv.available, file=file.path(argv[1],'data/cache.rda'),eval.promises=T)
+save(debian_pkgs, base_pkgs, available, ctv.available, file=file.path(cache_root,'cache.rda'),eval.promises=T)
diff --git a/pkg/trunk/inst/doc/README b/pkg/trunk/inst/doc/README
index 9b1c581..c514b3c 100644
--- a/pkg/trunk/inst/doc/README
+++ b/pkg/trunk/inst/doc/README
@@ -18,7 +18,9 @@ Let ROOT be the value returned by running: cran2deb root
     $ rm ROOT/var/archive
     $ ln -s /var/www/cran2deb/ ROOT/var/archive
 3. modify OTHERMIRROR of ROOT/etc/pbuilderrc.in to point to your webserver
-4. run: cran2deb update
-5. Try building a simple package: cran2deb build zoo
-   (The result will be in ROOT/var/results)
+4. cran2deb needs a persistent cache outside of R's control. therefore, create
+    /var/cache/cran2deb, writable by whichever user(s) will run cran2deb.
+5. run: cran2deb update
+6. Try building a simple package: cran2deb build zoo
+   (The result will be in /var/cache/cran2deb/results)
 
diff --git a/pkg/trunk/inst/etc/pbuilderrc.in b/pkg/trunk/inst/etc/pbuilderrc.in
index 425c0a4..cd553bd 100644
--- a/pkg/trunk/inst/etc/pbuilderrc.in
+++ b/pkg/trunk/inst/etc/pbuilderrc.in
@@ -1,6 +1,6 @@
 BASETGZ=/var/cache/pbuilder/base-cran2deb.tgz
 HOOKDIR=@ROOT@/etc/hook
-BUILDRESULT=@ROOT@/var/results
+BUILDRESULT=/var/cache/cran2deb/results
 EXTRAPACKAGES='debhelper r-base-dev cdbs r-base-core lintian xvfb xauth xfonts-base'
 REMOVEPACKAGES='lilo libldap-2.4-2 libopencdk10 libsasl2-2'
 # don't actually need aptitude, but pbuilder insists...
-- 
2.39.5