Package: sbuild
Version: 0.59.1-1
Severity: wishlist
Tags: patch

For most sbuild commands it doesn't make sense to run them against a cloned session chroot, as these get purged and changes will be gone.
The only exception is sbuild-shell.

The attached patch is against current git HEAD
361d275e9bf200f3bdacd78b7ecf267847d20a18

Jan-Marek Glogowski
commit 4d3714dfea7db251a9ac221f004850161a78e5b1
Author: Jan-Marek Glogowski <glo...@fbihome.de>
Date:   Thu Jan 21 13:36:15 2010 +0100

    Run most commands on -source chroots
    
    For most sbuild commands it doesn't make sense to run them
    against a cloned session chroot, as these get purged and changes
    will be gone. The only exception is sbuild-shell.
    
    So this adds an additional parameter to Utility::setup to
    indicate, if the command should automatically use the source
    chroot, if available.

diff --git a/bin/sbuild-apt b/bin/sbuild-apt
index f9ea814..9f06c41 100755
--- a/bin/sbuild-apt
+++ b/bin/sbuild-apt
@@ -48,7 +48,8 @@ if ($command eq "apt-get") {
 		"Bad command $command.  Allowed commands: apt-get or apt-cache\n");
 }
 
-my $session = setup($chroot, $conf) or die "Chroot setup failed";
+my $session = setup($chroot, $conf, 1) 
+    or die "Chroot setup failed for $chroot chroot";
 
 $session->run_apt_command(
     { COMMAND => [$command, @ARGV],
diff --git a/bin/sbuild-checkpackages b/bin/sbuild-checkpackages
index 00a47ce..d1b1350 100755
--- a/bin/sbuild-checkpackages
+++ b/bin/sbuild-checkpackages
@@ -69,12 +69,13 @@ usage_error("sbuild-checkpackages", "--list or --set must be specified")
 usage_error("sbuild-checkpackages", "A chroot must be specified")
     if (@ARGV != 1);
 
-my $chroot = $ARGV[0];
+my $chroot = shift @ARGV;
 
 setlocale(LC_COLLATE, "POSIX");
 $ENV{'LC_COLLATE'} = "POSIX";
 
-my $session = setup($chroot, $conf) or die "Chroot setup failed";
+my $session = setup($chroot, $conf, 1)
+    or die "Chroot setup failed for $chroot chroot";
 
 check_packages($session, $mode);
 
diff --git a/bin/sbuild-clean b/bin/sbuild-clean
index b7e65ab..6d42776 100755
--- a/bin/sbuild-clean
+++ b/bin/sbuild-clean
@@ -104,11 +104,10 @@ if ( ! $conf->get('CLEAN') && ! $conf->get('AUTOCLEAN') &&
 
 usage_error("sbuild-clean", "Incorrect number of options") if (@ARGV < 1);
 
-foreach (@ARGV) {
+foreach my $chroot (@ARGV) {
 
-    my $chroot = Sbuild::Utility::get_dist($_);
-
-    my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+    my $session = setup($chroot, $conf, 1) 
+	or die "Chroot setup failed for $chroot chroot";
 
     if ($conf->get('CLEAN')) {
 	print "Performing clean.\n";
diff --git a/bin/sbuild-distupgrade b/bin/sbuild-distupgrade
index 5e8cad7..6cab59f 100755
--- a/bin/sbuild-distupgrade
+++ b/bin/sbuild-distupgrade
@@ -36,11 +36,10 @@ $conf->check_group_membership();
 
 usage_error("sbuild-distupgrade", "Incorrect number of options") if (@ARGV < 1);
 
-foreach (@ARGV) {
+foreach my $chroot (@ARGV) {
 
-    my $chroot = Sbuild::Utility::get_dist($_);
-
-    my $session = setup($_, $conf) or die "Chroot setup failed for $chroot chroot";
+    my $session = setup($chroot, $conf, 1)
+	or die "Chroot setup failed for $chroot chroot";
 
     my $status = distupgrade($session, $conf);
     $status >>= 8;
diff --git a/bin/sbuild-hold b/bin/sbuild-hold
index 80f5aa3..96d808e 100755
--- a/bin/sbuild-hold
+++ b/bin/sbuild-hold
@@ -37,9 +37,10 @@ $conf->check_group_membership();
 
 usage_error("sbuild-hold", "Incorrect number of options") if (@ARGV < 2);
 
-my $chroot = Sbuild::Utility::get_dist($ARGV[0]);
+my $chroot = shift @ARGV;
 
-my $session = setup($ARGV[0], $conf) or die "Chroot setup failed for $chroot chroot";
+my $session = setup($chroot, $conf, 1)
+    or die "Chroot setup failed for $chroot chroot";
 
 print STDOUT "Holding packages in $chroot chroot:";
 shift @ARGV;
diff --git a/bin/sbuild-shell b/bin/sbuild-shell
index e30b074..0b46f74 100755
--- a/bin/sbuild-shell
+++ b/bin/sbuild-shell
@@ -38,8 +38,10 @@ $conf->check_group_membership();
 
 usage_error("sbuild-shell", "Incorrect number of options") if (@ARGV != 1);
 
+my $chroot = shift @ARGV;
 
-my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+my $session = setup($chroot, $conf, 0)
+    or die "Chroot setup failed for $chroot chroot";
 
 my $status = shell($session, $conf);
 $status >>= 8;
diff --git a/bin/sbuild-unhold b/bin/sbuild-unhold
index 4168cb4..ee5abe5 100755
--- a/bin/sbuild-unhold
+++ b/bin/sbuild-unhold
@@ -37,9 +37,10 @@ $conf->check_group_membership();
 
 usage_error("sbuild-unhold", "Incorrect number of options") if (@ARGV < 2);
 
-my $chroot = Sbuild::Utility::get_dist($ARGV[0]);
+my $chroot = shift @ARGV;
 
-my $session = setup($ARGV[0], $conf) or die "Chroot setup failed for $chroot chroot";
+my $session = setup($chroot, $conf, 1)
+    or die "Chroot setup failed for $chroot chroot";;
 
 print STDOUT "Unholding packages in $chroot chroot:";
 shift @ARGV;
diff --git a/bin/sbuild-update b/bin/sbuild-update
index d6dac48..67b7c2c 100755
--- a/bin/sbuild-update
+++ b/bin/sbuild-update
@@ -36,11 +36,10 @@ $conf->check_group_membership();
 
 usage_error("sbuild-update", "Incorrect number of options") if (@ARGV < 1);
 
-foreach (@ARGV) {
+foreach my $chroot (@ARGV) {
 
-    my $chroot = Sbuild::Utility::get_dist($_);
-
-    my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+    my $session = setup($chroot, $conf, 1)
+	or die "Chroot setup failed for $chroot chroot";
 
     my $status = update($session, $conf);
     $status >>= 8;
diff --git a/bin/sbuild-upgrade b/bin/sbuild-upgrade
index 9017ad7..a56b8a5 100755
--- a/bin/sbuild-upgrade
+++ b/bin/sbuild-upgrade
@@ -36,11 +36,10 @@ $conf->check_group_membership();
 
 usage_error("sbuild-upgrade", "Incorrect number of options") if (@ARGV < 1);
 
-foreach (@ARGV) {
+foreach my $chroot (@ARGV) {
 
-    my $chroot = Sbuild::Utility::get_dist($_);
-
-    my $session = setup($_, $conf) or die "Chroot setup failed for $chroot chroot";
+    my $session = setup($chroot, $conf, 1)
+	or die "Chroot setup failed for $chroot chroot";
 
     my $status = upgrade($session, $conf);
     $status >>= 8;
diff --git a/lib/Sbuild/Utility.pm b/lib/Sbuild/Utility.pm
index 6ae6159..c94a51c 100644
--- a/lib/Sbuild/Utility.pm
+++ b/lib/Sbuild/Utility.pm
@@ -44,7 +44,7 @@ use Module::Load::Conditional qw(can_load); # Used to check for LWP::UserAgent
 use Time::HiRes qw ( time ); # Needed for high resolution timers
 
 sub get_dist ($);
-sub setup ($$);
+sub setup ($$$);
 sub cleanup ($);
 sub shutdown ($);
 
@@ -76,10 +76,10 @@ sub get_dist ($) {
     return $dist;
 }
 
-sub setup ($$) {
+sub setup ($$$) {
     my $chroot = shift;
     my $conf = shift;
-
+    my $want_source_chroot = shift;
 
     $conf->set('VERBOSE', 1);
     $conf->set('NOLOG', 1);
@@ -90,6 +90,16 @@ sub setup ($$) {
     my $chroot_info;
     if ($conf->get('CHROOT_MODE') eq 'schroot') {
 	$chroot_info = Sbuild::ChrootInfoSchroot->new($conf);
+	if ($want_source_chroot) {
+	    # If sessions are created using cloning, it doesn't make
+	    # sense to update the session, so use the source instead
+
+	    my $current_chroot_info = $chroot_info->get_info($chroot);
+	    if (($current_chroot_info->get('Session Cloned') == 1)
+		&& ($current_chroot_info->get('Session Purged') == 0)) {
+		$chroot .= '-source';
+	    }
+	}
     } else {
 	$chroot_info = Sbuild::ChrootInfoSudo->new($conf);
     }

Reply via email to