[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sbuild in squeeze



On Wed, Dec 29, 2010 at 10:42:23AM +0100, Philipp Kern wrote:
> Hi Roger,
> 
> On Mon, Nov 08, 2010 at 12:10:23PM +0000, Roger Leigh wrote:
> > sbuild in squeeze has been neglected for some time, and it contains
> > quite a large number of bugs and deficiencies.  This was mainly due
> > to the fact that I couldn't devote a huge amount of time to Debian
> > during my PhD, and I only found the time to begin addressing this
> > properly over the last two weeks.  The version in unstable now fixes
> > 34 bugs present in squeeze:
> 
> sorry that this issue was neglected so long.  However the changes are
> massive, which was one of the reasons we were overwhelmed by it.  As
> this point in the freeze we cannot accept such an update anymore, too.
> Given that sbuild is still moving in unstable is an indicator for us
> to err on the side of caution.
[...]

> On v3 support: that's definitely needed.  You listed two patches in
> <20101115210839.GJ15585@codelibre.net>.  If that's sufficient, that
> would be reasonable for a targetted fix for squeeze.

OK.

> What's needed to be able to use sbuild's functionality with the stable
> schroot?

sbuild needs to be aware of schroot namespaces.  I've been through all
the changes and pulled out the needed changes.  This needs changes to
the chroot code and the utility programs.  There's also a change to the
25nssdatabases script to stop it breaking with schroot 1.4.

I've cherry-picked all of the required changes and put them here for
your approval (diff also attached against debian/sbuild-0.60.0-2):

http://git.debian.org/?p=buildd-tools/sbuild.git;a=shortlog;h=refs/heads/sbuild-squeeze

This is about as minimal as it's possible to make and still have it
non-broken.

I'll need to do some testing since cherry-picking like this might have
resulted in some needed changes being missed out.  But the number of
features being changed is small and discrete, so testing should be
simple and definitive to prove it's working.  Once I'm convinced it's
working correctly, may I upload this to testing-proposed-updates?


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
diff --git a/bin/sbuild-apt b/bin/sbuild-apt
index f9ea814..c868a09 100755
--- a/bin/sbuild-apt
+++ b/bin/sbuild-apt
@@ -48,7 +48,7 @@ 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('source', $chroot, $conf) or die "Chroot setup failed";
 
 $session->run_apt_command(
     { COMMAND => [$command, @ARGV],
diff --git a/bin/sbuild-checkpackages b/bin/sbuild-checkpackages
index 00a47ce..663a61d 100755
--- a/bin/sbuild-checkpackages
+++ b/bin/sbuild-checkpackages
@@ -74,7 +74,7 @@ my $chroot = $ARGV[0];
 setlocale(LC_COLLATE, "POSIX");
 $ENV{'LC_COLLATE'} = "POSIX";
 
-my $session = setup($chroot, $conf) or die "Chroot setup failed";
+my $session = setup('source', $chroot, $conf) or die "Chroot setup failed";
 
 check_packages($session, $mode);
 
diff --git a/bin/sbuild-clean b/bin/sbuild-clean
index b7e65ab..41c6785 100755
--- a/bin/sbuild-clean
+++ b/bin/sbuild-clean
@@ -108,7 +108,7 @@ foreach (@ARGV) {
 
     my $chroot = Sbuild::Utility::get_dist($_);
 
-    my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+    my $session = setup('source', $chroot, $conf) or die "Chroot setup failed";
 
     if ($conf->get('CLEAN')) {
 	print "Performing clean.\n";
diff --git a/bin/sbuild-createchroot b/bin/sbuild-createchroot
index 8c76b3b..9e3211c 100755
--- a/bin/sbuild-createchroot
+++ b/bin/sbuild-createchroot
@@ -158,6 +158,9 @@ $conf->set('INCLUDE', add_items($conf->get('INCLUDE'),
 				"debfoster"));
 
 my $suite = $ARGV[0];
+# Create the target directory in advance so abs_path (which is buggy)
+# won't fail.  Remove if abs_path is replaced by something better.
+makedir($ARGV[1], 0700);
 my $target = abs_path($ARGV[1]);
 my $mirror = $ARGV[2];
 my $script = undef;
@@ -249,7 +252,7 @@ my $chrootname = "${suite}-" . $conf->get('ARCH') . "-sbuild";
 if (-d "/etc/schroot/chroot.d") {
     # TODO: Don't hardcode path
     my $SCHROOT_CONF =
-	new File::Temp( TEMPLATE => "$chrootname.XXXXXX",
+	new File::Temp( TEMPLATE => "$chrootname-XXXXXX",
 			DIR => "/etc/schroot/chroot.d",
 			UNLINK => 0)
 	or die "Can't open schroot configuration file: $!\n";
@@ -259,12 +262,9 @@ if (-d "/etc/schroot/chroot.d") {
 [$chrootname]
 type=directory
 description=Debian $suite/$arch autobuilder
-location=$target
-priority=3
+directory=$target
 groups=root,sbuild
 root-groups=root,sbuild
-run-setup-scripts=true
-run-exec-scripts=true
 EOF
 
     my ($personality, $personality_message);
diff --git a/bin/sbuild-distupgrade b/bin/sbuild-distupgrade
index 5e8cad7..115497e 100755
--- a/bin/sbuild-distupgrade
+++ b/bin/sbuild-distupgrade
@@ -40,7 +40,7 @@ foreach (@ARGV) {
 
     my $chroot = Sbuild::Utility::get_dist($_);
 
-    my $session = setup($_, $conf) or die "Chroot setup failed for $chroot chroot";
+    my $session = setup('source', $chroot, $conf) 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..329d273 100755
--- a/bin/sbuild-hold
+++ b/bin/sbuild-hold
@@ -39,7 +39,7 @@ usage_error("sbuild-hold", "Incorrect number of options") if (@ARGV < 2);
 
 my $chroot = Sbuild::Utility::get_dist($ARGV[0]);
 
-my $session = setup($ARGV[0], $conf) or die "Chroot setup failed for $chroot chroot";
+my $session = setup('source', $ARGV[0], $conf) 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..bfbe890 100755
--- a/bin/sbuild-shell
+++ b/bin/sbuild-shell
@@ -39,7 +39,7 @@ $conf->check_group_membership();
 usage_error("sbuild-shell", "Incorrect number of options") if (@ARGV != 1);
 
 
-my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+my $session = setup('source', $ARGV[0], $conf) or die "Chroot setup failed";
 
 my $status = shell($session, $conf);
 $status >>= 8;
diff --git a/bin/sbuild-unhold b/bin/sbuild-unhold
index 4168cb4..98877f3 100755
--- a/bin/sbuild-unhold
+++ b/bin/sbuild-unhold
@@ -39,7 +39,7 @@ usage_error("sbuild-unhold", "Incorrect number of options") if (@ARGV < 2);
 
 my $chroot = Sbuild::Utility::get_dist($ARGV[0]);
 
-my $session = setup($ARGV[0], $conf) or die "Chroot setup failed for $chroot chroot";
+my $session = setup('source', $ARGV[0], $conf) 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..403b182 100755
--- a/bin/sbuild-update
+++ b/bin/sbuild-update
@@ -40,7 +40,7 @@ foreach (@ARGV) {
 
     my $chroot = Sbuild::Utility::get_dist($_);
 
-    my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+    my $session = setup('source', $chroot, $conf) or die "Chroot setup failed";
 
     my $status = update($session, $conf);
     $status >>= 8;
diff --git a/bin/sbuild-upgrade b/bin/sbuild-upgrade
index 9017ad7..be691e8 100755
--- a/bin/sbuild-upgrade
+++ b/bin/sbuild-upgrade
@@ -40,7 +40,7 @@ foreach (@ARGV) {
 
     my $chroot = Sbuild::Utility::get_dist($_);
 
-    my $session = setup($_, $conf) or die "Chroot setup failed for $chroot chroot";
+    my $session = setup('source', $chroot, $conf) or die "Chroot setup failed for $chroot chroot";
 
     my $status = upgrade($session, $conf);
     $status >>= 8;
diff --git a/debian/changelog b/debian/changelog
index c29cbab..ce80f4b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,42 @@
+sbuild (0.60.0-2squeeze1) testing-proposed-updates; urgency=low
+
+  * Backport needed changes from unstable.  All changes are
+    cherry-picked from git master.
+  * dpkg-source v3 support:
+    - ba54dd62: Sbuild::Build: Remove DSC filename assumptions breaking
+                new source formats.
+      Improve dpkg-source v3 source format handling.  Don't hard-code
+      assumptions about how the source files are named
+      (Closes: #559533).
+    - 7594a18c: Sbuild::Build: Don't use '-sn' with
+                'dpkg-buildpackage -x'.
+      '-sn' is not supported by new source formats (Closes: #583337).
+  * schroot 1.4 support:
+    - 3426a619: Sbuild::ChrootInfoSchroot: Add find function which
+                copes with chroot namespaces
+    - bf2873f3: Sbuild::ChrootInfoSchroot: Parse chroot namespaces
+    - 6daaf332: Sbuild::ChrootInfo: Add support for namespaces
+    - 88f049b8: Sbuild::ChrootInfo: Support namespaces properly with
+                sudo
+    - 3531b5f6: Fix regression when passing source:<distribution> as
+                CHROOT for sbuild-update and friends
+    These changes add support for schroot 1.4 namespaces ('chroot',
+    'source' and 'session').
+  * 25nssdatabases comment handling from unstable:
+    - 860529f8: etc/25nssdatabases: Update from schroot 20nssdatabases
+    This allows the setup scripts to work with schroot 1.4 nssdatabases
+    files containing comments.
+  * sbuild-createchroot schroot 1.4 compatibility:
+    - d61a6551: sbuild-createchroot: Fix abs_path and remove deprecated
+                keys
+    - fcfea251: sbuild-createchroot: Document need for abs_path
+                workaround
+    - e0583348: bin/sbuild-createchroot: fix the schroot template
+    These changes allow sbuild-createchroot to create schroot
+    configurations compatible with schroot 1.4.
+
+ -- Roger Leigh <rleigh@debian.org>  Thu, 30 Dec 2010 11:18:08 +0000
+
 sbuild (0.60.0-2) unstable; urgency=low
 
   * sbuild:
diff --git a/debian/control b/debian/control
index 14c4792..6de2159 100644
--- a/debian/control
+++ b/debian/control
@@ -11,7 +11,7 @@ Vcs-Git: git://git.debian.org/git/buildd-tools/sbuild
 Package: libsbuild-perl
 Architecture: all
 Section: perl
-Depends: ${misc:Depends}, ${perl:Depends}, perl-modules, libfilesys-df-perl, adduser, apt, exim4 | mail-transport-agent, dpkg-dev, devscripts (>= 2.10.26), dctrl-tools, schroot (>= 1.1.6)
+Depends: ${misc:Depends}, ${perl:Depends}, perl-modules, libfilesys-df-perl, adduser, apt, exim4 | mail-transport-agent, dpkg-dev, devscripts (>= 2.10.26), dctrl-tools, schroot (>= 1.4.12)
 Replaces: sbuild (<= 0.58.4-1)
 Description: Tool for building Debian binary packages from Debian sources
  The sbuild suite of programs (wanna-build, buildd and sbuild) are
diff --git a/etc/25nssdatabases b/etc/25nssdatabases
index 783890d..c45e3fb 100755
--- a/etc/25nssdatabases
+++ b/etc/25nssdatabases
@@ -19,8 +19,6 @@
 
 set -e
 
-NSSDATABASES="/etc/sbuild/nssdatabases-defaults"
-
 if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then
     . "$CHROOT_SCRIPT_CONFIG"
 elif [ "$2" = "ok" ]; then
@@ -48,6 +46,23 @@ if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then
     if [ -n "$NSSDATABASES" ]; then
 	if [ -f "$NSSDATABASES" ]; then
 	    while read db; do
+		if echo "$db" | egrep -q '^(#|$)' ; then
+                    continue
+		fi
+
+                # Device and inode
+		dr=$(/usr/bin/stat --format="%d %i" "/etc/$db")
+                # This one can fail since it might not exist yet
+		dc=$(/usr/bin/stat --format="%d %i" "${CHROOT_PATH}/etc/$db" 2>/dev/null || :)
+
+                # If the database inside and outside the chroot is the
+                # same, it's very likely that dup_nss would blank the
+                # database, so skip it.
+		if [ "$dr" = "$dc" ]; then
+		    echo "warning: $db files '/etc/$db' and '${CHROOT_PATH}/etc/$db' are the same file; skipping" 1>&2
+                    continue;
+		fi
+
 		dup_nss "$db" "${CHROOT_PATH}/etc/$db"
 	    done < "$NSSDATABASES"
 	else
diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm
index d9cdbd7..b9842c8 100644
--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -44,7 +44,7 @@ use Sbuild::Sysconfig qw($version $release_date);
 use Sbuild::Conf;
 use Sbuild::LogBase qw($saved_stdout);
 use Sbuild::Sysconfig;
-use Sbuild::Utility qw(check_url download parse_file);
+use Sbuild::Utility qw(check_url download dsc_files);
 use Sbuild::AptitudeBuildDepSatisfier;
 use Sbuild::InternalBuildDepSatisfier;
 
@@ -229,7 +229,8 @@ sub run {
 	$chroot_info = Sbuild::ChrootInfoSudo->new($self->get('Config'));
     }
 
-    my $session = $chroot_info->create($self->get_conf('DISTRIBUTION'),
+    my $session = $chroot_info->create('chroot',
+				       $self->get_conf('DISTRIBUTION'),
 				       $self->get_conf('CHROOT'),
 				       $self->get_conf('ARCH'));
 
@@ -453,7 +454,7 @@ sub fetch_source_files {
     my $ver = $self->get('OVersion');
     my $arch = $self->get('Arch');
 
-    my ($files, @other_files, $dscarchs, $dscpkg, $dscver, @fetched);
+    my ($dscarchs, $dscpkg, $dscver, @fetched);
 
     my $build_depends = "";
     my $build_depends_indep = "";
@@ -479,7 +480,8 @@ sub fetch_source_files {
 	$file = download($self->get('DSC')) or
 	    $self->log_error("Could not download " . $self->get('DSC')) and
 	    return 0;
-	my @cwd_files = $self->dsc_files($file);
+	debug("Parsing $dsc\n");
+	my @cwd_files = dsc_files($file);
 	if (-f "$dir/$dsc") {
 	    # Copy the local source files into the build directory.
 	    $self->log_subsubsection("Local sources");
@@ -669,10 +671,6 @@ sub fetch_source_files {
     $dsctext =~ /^Version:\s*(.*)$/mi and $dscver = $1;
     $self->set_version("${dscpkg}_${dscver}");
 
-    $dsctext =~ /^Files:\s*\n((\s+.*\s*\n)+)/mi and $files = $1;
-    @other_files = map { (split( /\s+/, $_ ))[3] } split( "\n", $files );
-    $files =~ /(\Q$pkg\E.*orig.tar.gz)/mi and $orig = $1;
-
     $self->log_subsubsection("Check arch");
     if (!$dscarchs) {
 	$self->log("$dsc has no Architecture: field -- skipping arch check!\n");
@@ -712,19 +710,15 @@ sub build {
 
     my $dscfile = $self->get('DSC File');
     my $dscdir = $self->get('DSC Dir');
-    my $pkgv = $self->get('Package_Version');
+    my $pkg = $self->get('Package');
     my $build_dir = $self->get('Chroot Build Dir');
     my $arch = $self->get('Arch');
 
     my( $rv, $changes );
     local( *PIPE, *F, *F2 );
 
-    $pkgv = $self->fixup_pkgv($pkgv);
     $self->log_subsection("Build");
     $self->set('This Space', 0);
-    $pkgv =~ /^([a-zA-Z\d.+-]+)_([a-zA-Z\d:.+~-]+)/;
-    # Note, this version contains ".dsc".
-    my ($pkg, $version) = ($1,$2);
 
     my $tmpunpackdir = $dscdir;
     $tmpunpackdir =~ s/-.*$/.orig.tmp-nest/;
@@ -748,7 +742,7 @@ sub build {
 	$self->set('Sub Task', "dpkg-source");
 	$self->get('Session')->run_command(
 		    { COMMAND => [$self->get_conf('DPKG_SOURCE'),
-				  '-sn', '-x', $dscfile, $dscdir],
+				  '-x', $dscfile, $dscdir],
 		      USER => $self->get_conf('USERNAME'),
 		      CHROOT => 1,
 		      PRIORITY => 0});
@@ -1793,18 +1787,6 @@ sub check_watches {
     $self->log("\n");
 }
 
-
-sub fixup_pkgv {
-    my $self = shift;
-    my $pkgv = shift;
-
-    $pkgv =~ s,^.*/,,; # strip path
-    $pkgv =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
-    $pkgv =~ s/_[a-zA-Z\d+~-]+\.(changes|deb)$//; # strip extension
-
-    return $pkgv;
-}
-
 sub format_deps {
     my $self = shift;
 
@@ -1919,26 +1901,6 @@ sub debian_files_list {
     return @list;
 }
 
-sub dsc_files {
-    my $self = shift;
-    my $dsc = shift;
-    my @files;
-
-    debug("Parsing $dsc\n");
-
-    # The parse_file() subroutine returns a ref to an array of hashrefs.
-    my $stanzas = parse_file($dsc);
-
-    # A dsc file would only ever contain one stanza, so we only deal with
-    # the first entry which is a ref to a hash of fields for the stanza.
-    my $stanza = @{$stanzas}[0];
-
-    # We're only interested in the name of the files in the Files field.
-    my $entry = ${$stanza}{'Files'};
-    @files = grep(/\.tar\.gz$|\.diff\.gz$/, split(/\s/, $entry));
-
-    return @files;
-}
 
 # Figure out chroot architecture
 sub chroot_arch {
diff --git a/lib/Sbuild/ChrootInfo.pm b/lib/Sbuild/ChrootInfo.pm
index e5db3a1..a107572 100644
--- a/lib/Sbuild/ChrootInfo.pm
+++ b/lib/Sbuild/ChrootInfo.pm
@@ -57,11 +57,12 @@ sub new {
 
 sub create {
     my $self = shift;
+    my $namespace = shift;
     my $distribution = shift;
     my $chroot = shift;
     my $arch = shift;
 
-    my $chrootid = $self->find($distribution, $chroot, $arch);
+    my $chrootid = $self->find($namespace, $distribution, $chroot, $arch);
 
     my $newchroot = $self->_create($chrootid);
 
@@ -75,12 +76,18 @@ sub create {
 
 sub find {
     my $self = shift;
+    my $namespace = shift;
     my $distribution = shift;
     my $chroot = shift;
     my $arch = shift;
 
-    my $chroots = $self->get('Chroots');
+    # Use namespace given from $distribution if one is found
+    if ($distribution =~ /^([^:]+):/msx) {
+	$namespace = $1;
+	$distribution =~ s/^[^:]+://msx;
+    }
 
+    my $chroots = $self->get('Chroots');
 
     # Don't do strict arch checking if ARCH == HOST_ARCH.
     if (!defined($arch) || $arch eq "") {
@@ -91,20 +98,31 @@ sub find {
     my $arch_found = 0;
 
     if (!defined $chroot) {
+	my $ns = $chroots->{$namespace};
+	if (!defined($ns)) {
+	    if ($namespace ne 'chroot') {
+		$chroot = $self->find('chroot', $distribution, $chroot, $arch);
+	    } else {
+		# TODO: Return error, rather than die.
+		die "Chroot namespace $namespace not found\n";
+		return undef;
+	    }
+	}
+
         if ($arch ne "" &&
-            defined($chroots->{"${distribution}-${arch}-sbuild"})) {
-            $chroot = "${distribution}-${arch}-sbuild";
+            defined($ns->{"${distribution}-${arch}-sbuild"})) {
+            $chroot = "${namespace}:${distribution}-${arch}-sbuild";
             $arch_found = 1;
         }
-        elsif (defined($chroots->{"${distribution}-sbuild"})) {
-            $chroot = "${distribution}-sbuild";
+        elsif (defined($ns->{"${distribution}-sbuild"})) {
+            $chroot = "${namespace}:${distribution}-sbuild";
         }
         elsif ($arch ne "" &&
-               defined($chroots->{"${distribution}-${arch}"})) {
-            $chroot = "${distribution}-${arch}";
+               defined($ns->{"${distribution}-${arch}"})) {
+            $chroot = "${namespace}:${distribution}-${arch}";
             $arch_found = 1;
-        } elsif (defined($chroots->{$distribution})) {
-            $chroot = $distribution;
+        } elsif (defined($ns->{$distribution})) {
+            $chroot = "${namespace}:${distribution}";
 	}
 
 	if ($arch_set && !$arch_found && $arch ne "") {
@@ -115,9 +133,14 @@ sub find {
     }
 
     if (!$chroot) {
-	# TODO: Return error, rather than die.
-	die "Chroot for distribution $distribution, architecture $arch not found\n";
-	return undef;
+	# Fall back to chroot namespace.
+	if ($namespace ne 'chroot') {
+	    $chroot = $self->find('chroot', $distribution, $chroot, $arch);
+	} else {
+	    # TODO: Return error, rather than die.
+	    die "Chroot for distribution $distribution, architecture $arch not found\n";
+	    return undef;
+	}
     }
 
     return $chroot;
diff --git a/lib/Sbuild/ChrootInfoSchroot.pm b/lib/Sbuild/ChrootInfoSchroot.pm
index 1cc0e49..73213f4 100644
--- a/lib/Sbuild/ChrootInfoSchroot.pm
+++ b/lib/Sbuild/ChrootInfoSchroot.pm
@@ -50,7 +50,8 @@ sub get_info_from_stream {
     my $stream = shift;
 
     my $chroot_type = '';
-    my %tmp = ('Name' => '',
+    my %tmp = ('Namespace' => '',
+	       'Name' => '',
 	       'Priority' => 0,
 	       'Location' => '',
 	       'Session Purged' => 0);
@@ -60,6 +61,30 @@ sub get_info_from_stream {
 
 	last if ! $_;
 
+	if (/\s*─── Chroot ───/ &&
+	    $tmp{'Namespace'} eq "") {
+	    $tmp{'Namespace'} = 'chroot';
+	}
+	if (/\s*─── Session ───/ &&
+	    $tmp{'Namespace'} eq "") {
+	    $tmp{'Namespace'} = 'session';
+	}
+	if (/\s*─── Source ───/ &&
+	    $tmp{'Namespace'} eq "") {
+	    $tmp{'Namespace'} = 'source';
+	}
+	if (/\s*--- Chroot ---/ &&
+	    $tmp{'Namespace'} eq "") {
+	    $tmp{'Namespace'} = 'chroot';
+	}
+	if (/\s*--- Session ---/ &&
+	    $tmp{'Namespace'} eq "") {
+	    $tmp{'Namespace'} = 'session';
+	}
+	if (/\s*--- Source ---/ &&
+	    $tmp{'Namespace'} eq "") {
+	    $tmp{'Namespace'} = 'source';
+	}
 	if (/^\s*Name:?\s+(.*)$/ &&
 	    $tmp{'Name'} eq "") {
 	    $tmp{'Name'} = $1;
@@ -92,13 +117,16 @@ sub get_info_from_stream {
 	}
     }
 
-    if ($self->get_conf('DEBUG')) {
-	print STDERR "Found schroot chroot: $tmp{'Name'}\n";
+    if ($self->get_conf('DEBUG') && $tmp{'Name'})  {
+	print STDERR "Found schroot chroot: $tmp{'Namespace'}:$tmp{'Name'}\n";
 	foreach (sort keys %tmp) {
 	    print STDERR "  $_ $tmp{$_}\n";
 	}
     }
 
+    if (!$tmp{'Name'}) {
+	return undef;
+    }
     return \%tmp;
 }
 
@@ -129,13 +157,18 @@ sub get_info_all {
     $ENV{'LC_ALL'} = 'C';
     $ENV{'LANGUAGE'} = 'C';
 
-    open CHROOTS, '-|', $self->get_conf('SCHROOT'), '--info', '--all-chroots'
+    open CHROOTS, '-|', $self->get_conf('SCHROOT'), '--info'
 	or die 'Can\'t run ' . $self->get_conf('SCHROOT');
-    while (<CHROOTS>) {
-	my $tmp = $self->get_info_from_stream(\*CHROOTS);
-	$chroots->{$tmp->{'Name'}} = $tmp;
+    my $tmp = undef;
+    while (defined($tmp = $self->get_info_from_stream(\*CHROOTS))) {
+	my $namespace = $tmp->{'Namespace'};
+	$namespace = "chroot"
+	    if !$tmp->{'Namespace'};
+	$chroots->{$namespace} = {}
+	    if (!exists($chroots->{$namespace}));
+	$chroots->{$namespace}->{$tmp->{'Name'}} = $tmp;
 	foreach my $alias (split(/\s+/, $tmp->{'Aliases'})) {
-	    $chroots->{$alias} = $tmp;
+	    $chroots->{$namespace}->{$alias} = $tmp;
 	}
     }
     close CHROOTS or die "Can't close schroot pipe";
diff --git a/lib/Sbuild/ChrootInfoSudo.pm b/lib/Sbuild/ChrootInfoSudo.pm
index f4e18d6..5e0d28f 100644
--- a/lib/Sbuild/ChrootInfoSudo.pm
+++ b/lib/Sbuild/ChrootInfoSudo.pm
@@ -49,13 +49,28 @@ sub get_info {
     my $self = shift;
     my $chroot = shift;
 
-    return $self->get('Chroots')->{$chroot};
+    $chroot =~ /(\S+):(\S+)/;
+    my ($namespace, $chrootname) = ($1, $2);
+
+    my $info = undef;
+
+    if (exists($self->get('Chroots')->{$namespace}) &&
+	defined($self->get('Chroots')->{$namespace}) &&
+	exists($self->get('Chroots')->{$namespace}->{$chrootname})) {
+	$info = $self->get('Chroots')->{$namespace}->{$chrootname}
+    }
+
+    return $info;
 }
 
 sub get_info_all {
     my $self = shift;
 
     my $chroots = {};
+    # All sudo chroots are in the chroot namespace.
+    my $namespace = "chroot";
+    $chroots->{$namespace} = {};
+
     my $build_dir = $self->get_conf('BUILD_DIR');
 
     # TODO: Configure $build_dir as $sudo_chroot_dir
@@ -79,7 +94,10 @@ sub get_info_all {
 		}
 	    }
 
-	    $chroots->{$name} = \%tmp;
+	    $tmp{'Name'} = $name;
+	    $tmp{'Namespace'} = $namespace;
+
+	    $chroots->{$namespace}->{$name} = \%tmp;
 	}
     }
 
diff --git a/lib/Sbuild/Utility.pm b/lib/Sbuild/Utility.pm
index 6ae6159..7a4bbd2 100644
--- a/lib/Sbuild/Utility.pm
+++ b/lib/Sbuild/Utility.pm
@@ -44,9 +44,11 @@ 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 ($);
+sub parse_file ($);
+sub dsc_files ($);
 
 my $current_session;
 
@@ -56,7 +58,7 @@ BEGIN {
 
     @ISA = qw(Exporter);
 
-    @EXPORT = qw(setup cleanup shutdown check_url download parse_file);
+    @EXPORT = qw(setup cleanup shutdown check_url download parse_file dsc_files);
 
     $SIG{'INT'} = \&shutdown;
     $SIG{'TERM'} = \&shutdown;
@@ -76,11 +78,11 @@ sub get_dist ($) {
     return $dist;
 }
 
-sub setup ($$) {
+sub setup ($$$) {
+    my $namespace = shift;
     my $chroot = shift;
     my $conf = shift;
 
-
     $conf->set('VERBOSE', 1);
     $conf->set('NOLOG', 1);
 
@@ -96,7 +98,8 @@ sub setup ($$) {
 
     my $session;
 
-    $session = $chroot_info->create($chroot,
+    $session = $chroot_info->create($namespace,
+				    $chroot,
 				    undef, # TODO: Add --chroot option
 				    $conf->get('ARCH'));
 
@@ -358,7 +361,7 @@ sub _get_proxy {
 # It can also be used on files like Packages or Sources files in a Debian
 # archive.
 # This subroutine returns an array of hashes. Each hash is a stanza.
-sub parse_file {
+sub parse_file ($) {
     # Takes one parameter, the file to parse.
     my ($file) = @_;
 
@@ -420,4 +423,26 @@ sub parse_file {
     return \@array_of_fields;
 }
 
+sub dsc_files ($) {
+    my $dsc = shift;
+
+    my @files;
+
+    # The parse_file() subroutine returns a ref to an array of hashrefs.
+    my $stanzas = parse_file($dsc);
+
+    # A dsc file would only ever contain one stanza, so we only deal with
+    # the first entry which is a ref to a hash of fields for the stanza.
+    my $stanza = @{$stanzas}[0];
+
+    # We're only interested in the name of the files in the Files field.
+    my $entry = ${$stanza}{'Files'};
+
+    foreach my $line (split("\n", $entry)) {
+	push @files, $1 if $line =~ /(\S+)\s*$/;
+    }
+
+    return @files;
+}
+
 1;

Attachment: signature.asc
Description: Digital signature


Reply to: