launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27889
[Merge] ~cjwatson/launchpad-buildd:backend-find-empty-output into launchpad-buildd:master
Colin Watson has proposed merging ~cjwatson/launchpad-buildd:backend-find-empty-output into launchpad-buildd:master.
Commit message:
Fix handling of empty output in Backend.find
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/413676
`Backend.find` mishandled empty output (i.e. if no paths were matched): in that case it returned `['']`. It now correctly returns `[]` instead.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:backend-find-empty-output into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index 7a5dcb1..cf63e39 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ launchpad-buildd (206) UNRELEASED; urgency=medium
* Fix flake8 violations.
* Refactor extra status handling to be common to all build types.
+ * Fix handling of empty output in Backend.find.
-- Colin Watson <cjwatson@xxxxxxxxxx> Wed, 08 Dec 2021 15:42:26 +0000
diff --git a/lpbuildd/target/backend.py b/lpbuildd/target/backend.py
index a7e778e..fb00dd4 100644
--- a/lpbuildd/target/backend.py
+++ b/lpbuildd/target/backend.py
@@ -146,7 +146,7 @@ class Backend:
if name is not None:
cmd.extend(["-name", name])
cmd.extend(["-printf", "%P\\0"])
- paths = self.run(cmd, get_output=True).rstrip(b"\0").split(b"\0")
+ paths = self.run(cmd, get_output=True).split(b"\0")[:-1]
# XXX cjwatson 2017-08-04: Use `os.fsdecode` instead once we're on
# Python 3.
return [p.decode("UTF-8") for p in paths]
diff --git a/lpbuildd/target/tests/test_chroot.py b/lpbuildd/target/tests/test_chroot.py
index 8004fa9..10483e1 100644
--- a/lpbuildd/target/tests/test_chroot.py
+++ b/lpbuildd/target/tests/test_chroot.py
@@ -255,6 +255,7 @@ class TestChroot(TestCase):
{"stdout": io.BytesIO(b"foo\0bar\0")},
{"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},
{"stdout": io.BytesIO(b"bar\0bar/bar\0")},
+ {"stdout": io.BytesIO(b"")},
])
processes_fixture.add(lambda _: next(test_proc_infos), name="sudo")
self.assertEqual(
@@ -270,6 +271,9 @@ class TestChroot(TestCase):
self.assertEqual(
["bar", "bar/bar"],
Chroot("1", "xenial", "amd64").find("/path", name="bar"))
+ self.assertEqual(
+ [],
+ Chroot("1", "xenial", "amd64").find("/path", name="nonexistent"))
find_prefix = [
"sudo", "/usr/sbin/chroot",
@@ -282,6 +286,7 @@ class TestChroot(TestCase):
find_prefix + ["-maxdepth", "1"] + find_suffix,
find_prefix + ["!", "-type", "d"] + find_suffix,
find_prefix + ["-name", "bar"] + find_suffix,
+ find_prefix + ["-name", "nonexistent"] + find_suffix,
]
self.assertEqual(
expected_args,
diff --git a/lpbuildd/target/tests/test_lxd.py b/lpbuildd/target/tests/test_lxd.py
index 35be3bb..15b2f1c 100644
--- a/lpbuildd/target/tests/test_lxd.py
+++ b/lpbuildd/target/tests/test_lxd.py
@@ -797,6 +797,7 @@ class TestLXD(TestCase):
{"stdout": io.BytesIO(b"foo\0bar\0")},
{"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},
{"stdout": io.BytesIO(b"bar\0bar/bar\0")},
+ {"stdout": io.BytesIO(b"")},
])
processes_fixture.add(lambda _: next(test_proc_infos), name="lxc")
self.assertEqual(
@@ -812,6 +813,8 @@ class TestLXD(TestCase):
self.assertEqual(
["bar", "bar/bar"],
LXD("1", "xenial", "amd64").find("/path", name="bar"))
+ self.assertEqual(
+ [], LXD("1", "xenial", "amd64").find("/path", name="nonexistent"))
find_prefix = [
"lxc", "exec", "lp-xenial-amd64", "--",
@@ -823,6 +826,7 @@ class TestLXD(TestCase):
find_prefix + ["-maxdepth", "1"] + find_suffix,
find_prefix + ["!", "-type", "d"] + find_suffix,
find_prefix + ["-name", "bar"] + find_suffix,
+ find_prefix + ["-name", "nonexistent"] + find_suffix,
]
self.assertEqual(
expected_args,