Merge ~cjwatson/launchpad-buildd:backend-find-empty-output into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: b79092a650ef667d09794a87f015ef0a366de236
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:backend-find-empty-output
Merge into: launchpad-buildd:master
Diff against target: 84 lines (+11/-1)
4 files modified
debian/changelog (+1/-0)
lpbuildd/target/backend.py (+1/-1)
lpbuildd/target/tests/test_chroot.py (+5/-0)
lpbuildd/target/tests/test_lxd.py (+4/-0)
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+413676@code.launchpad.net

Commit message

Fix handling of empty output in Backend.find

Description of the change

`Backend.find` mishandled empty output (i.e. if no paths were matched): in that case it returned `['']`. It now correctly returns `[]` instead.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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
22
3 * Fix flake8 violations.3 * Fix flake8 violations.
4 * Refactor extra status handling to be common to all build types.4 * Refactor extra status handling to be common to all build types.
5 * Fix handling of empty output in Backend.find.
56
6 -- Colin Watson <cjwatson@ubuntu.com> Wed, 08 Dec 2021 15:42:26 +00007 -- Colin Watson <cjwatson@ubuntu.com> Wed, 08 Dec 2021 15:42:26 +0000
78
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:
146 if name is not None:146 if name is not None:
147 cmd.extend(["-name", name])147 cmd.extend(["-name", name])
148 cmd.extend(["-printf", "%P\\0"])148 cmd.extend(["-printf", "%P\\0"])
149 paths = self.run(cmd, get_output=True).rstrip(b"\0").split(b"\0")149 paths = self.run(cmd, get_output=True).split(b"\0")[:-1]
150 # XXX cjwatson 2017-08-04: Use `os.fsdecode` instead once we're on150 # XXX cjwatson 2017-08-04: Use `os.fsdecode` instead once we're on
151 # Python 3.151 # Python 3.
152 return [p.decode("UTF-8") for p in paths]152 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):
255 {"stdout": io.BytesIO(b"foo\0bar\0")},255 {"stdout": io.BytesIO(b"foo\0bar\0")},
256 {"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},256 {"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},
257 {"stdout": io.BytesIO(b"bar\0bar/bar\0")},257 {"stdout": io.BytesIO(b"bar\0bar/bar\0")},
258 {"stdout": io.BytesIO(b"")},
258 ])259 ])
259 processes_fixture.add(lambda _: next(test_proc_infos), name="sudo")260 processes_fixture.add(lambda _: next(test_proc_infos), name="sudo")
260 self.assertEqual(261 self.assertEqual(
@@ -270,6 +271,9 @@ class TestChroot(TestCase):
270 self.assertEqual(271 self.assertEqual(
271 ["bar", "bar/bar"],272 ["bar", "bar/bar"],
272 Chroot("1", "xenial", "amd64").find("/path", name="bar"))273 Chroot("1", "xenial", "amd64").find("/path", name="bar"))
274 self.assertEqual(
275 [],
276 Chroot("1", "xenial", "amd64").find("/path", name="nonexistent"))
273277
274 find_prefix = [278 find_prefix = [
275 "sudo", "/usr/sbin/chroot",279 "sudo", "/usr/sbin/chroot",
@@ -282,6 +286,7 @@ class TestChroot(TestCase):
282 find_prefix + ["-maxdepth", "1"] + find_suffix,286 find_prefix + ["-maxdepth", "1"] + find_suffix,
283 find_prefix + ["!", "-type", "d"] + find_suffix,287 find_prefix + ["!", "-type", "d"] + find_suffix,
284 find_prefix + ["-name", "bar"] + find_suffix,288 find_prefix + ["-name", "bar"] + find_suffix,
289 find_prefix + ["-name", "nonexistent"] + find_suffix,
285 ]290 ]
286 self.assertEqual(291 self.assertEqual(
287 expected_args,292 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):
797 {"stdout": io.BytesIO(b"foo\0bar\0")},797 {"stdout": io.BytesIO(b"foo\0bar\0")},
798 {"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},798 {"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},
799 {"stdout": io.BytesIO(b"bar\0bar/bar\0")},799 {"stdout": io.BytesIO(b"bar\0bar/bar\0")},
800 {"stdout": io.BytesIO(b"")},
800 ])801 ])
801 processes_fixture.add(lambda _: next(test_proc_infos), name="lxc")802 processes_fixture.add(lambda _: next(test_proc_infos), name="lxc")
802 self.assertEqual(803 self.assertEqual(
@@ -812,6 +813,8 @@ class TestLXD(TestCase):
812 self.assertEqual(813 self.assertEqual(
813 ["bar", "bar/bar"],814 ["bar", "bar/bar"],
814 LXD("1", "xenial", "amd64").find("/path", name="bar"))815 LXD("1", "xenial", "amd64").find("/path", name="bar"))
816 self.assertEqual(
817 [], LXD("1", "xenial", "amd64").find("/path", name="nonexistent"))
815818
816 find_prefix = [819 find_prefix = [
817 "lxc", "exec", "lp-xenial-amd64", "--",820 "lxc", "exec", "lp-xenial-amd64", "--",
@@ -823,6 +826,7 @@ class TestLXD(TestCase):
823 find_prefix + ["-maxdepth", "1"] + find_suffix,826 find_prefix + ["-maxdepth", "1"] + find_suffix,
824 find_prefix + ["!", "-type", "d"] + find_suffix,827 find_prefix + ["!", "-type", "d"] + find_suffix,
825 find_prefix + ["-name", "bar"] + find_suffix,828 find_prefix + ["-name", "bar"] + find_suffix,
829 find_prefix + ["-name", "nonexistent"] + find_suffix,
826 ]830 ]
827 self.assertEqual(831 self.assertEqual(
828 expected_args,832 expected_args,

Subscribers

People subscribed via source and target branches