← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad-buildd/chroot-top-level-dir into lp:launchpad-buildd

 

Colin Watson has proposed merging lp:~cjwatson/launchpad-buildd/chroot-top-level-dir into lp:launchpad-buildd.

Commit message:
Tolerate chroot tarballs with a top-level directory other than chroot-autobuild/.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/chroot-top-level-dir/+merge/342833

This makes things a little more flexible in the face of different ways of generating chroot tarballs.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad-buildd/chroot-top-level-dir into lp:launchpad-buildd.
=== modified file 'debian/changelog'
--- debian/changelog	2018-04-04 16:25:31 +0000
+++ debian/changelog	2018-04-07 23:23:06 +0000
@@ -1,6 +1,8 @@
 launchpad-buildd (161) UNRELEASED; urgency=medium
 
   * Pass build URL to snapcraft using SNAPCRAFT_IMAGE_INFO.
+  * Tolerate chroot tarballs with a top-level directory other than
+    chroot-autobuild/.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Wed, 04 Apr 2018 17:03:14 +0100
 

=== modified file 'lpbuildd/target/chroot.py'
--- lpbuildd/target/chroot.py	2017-11-10 20:55:33 +0000
+++ lpbuildd/target/chroot.py	2018-04-07 23:23:06 +0000
@@ -31,7 +31,9 @@
     def create(self, tarball_path):
         """See `Backend`."""
         subprocess.check_call(
-            ["sudo", "tar", "-C", self.build_path, "-xf", tarball_path])
+            ["sudo", "tar", "-C", self.build_path,
+             "--transform", "s,[^/]*,chroot-autobuild,",
+             "-xf", tarball_path])
 
     def start(self):
         """See `Backend`."""

=== modified file 'lpbuildd/target/lxd.py'
--- lpbuildd/target/lxd.py	2018-02-04 00:15:39 +0000
+++ lpbuildd/target/lxd.py	2018-04-07 23:23:06 +0000
@@ -124,7 +124,8 @@
             return False
 
     def _convert(self, source_tarball, target_tarball):
-        creation_time = source_tarball.getmember("chroot-autobuild").mtime
+        first_entry = next(iter(source_tarball))
+        creation_time = first_entry.mtime
         metadata = {
             "architecture": self.lxc_arch,
             "creation_date": creation_time,
@@ -147,11 +148,15 @@
 
         # Mangle the chroot tarball into the form needed by LXD: when using
         # the combined metadata/rootfs form, the rootfs must be under
-        # rootfs/ rather than under chroot-autobuild/.
+        # rootfs/ rather than under chroot-autobuild/ or anything else.
         for entry in source_tarball:
             fileptr = None
             try:
-                orig_name = entry.name.split("chroot-autobuild", 1)[-1]
+                orig_name_bits = entry.name.split("/", 1)
+                if len(orig_name_bits) > 1:
+                    orig_name = "/" + orig_name_bits[1]
+                else:
+                    orig_name = ""
                 entry.name = "rootfs" + orig_name
 
                 if entry.isfile():
@@ -162,8 +167,7 @@
                 elif entry.islnk():
                     # Update hardlinks to point to the right target
                     entry.linkname = (
-                        "rootfs" +
-                        entry.linkname.split("chroot-autobuild", 1)[-1])
+                        "rootfs/" + entry.linkname.split("/", 1)[-1])
 
                 target_tarball.addfile(entry, fileobj=fileptr)
             finally:

=== modified file 'lpbuildd/target/tests/test_chroot.py'
--- lpbuildd/target/tests/test_chroot.py	2017-11-01 23:04:53 +0000
+++ lpbuildd/target/tests/test_chroot.py	2018-04-07 23:23:06 +0000
@@ -39,6 +39,7 @@
 
         expected_args = [
             ["sudo", "tar", "-C", "/expected/home/build-1",
+             "--transform", "s,[^/]*,chroot-autobuild,",
              "-xf", "/path/to/tarball"],
             ]
         self.assertEqual(