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
1diff --git a/debian/changelog b/debian/changelog
2index 7a5dcb1..cf63e39 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -2,6 +2,7 @@ launchpad-buildd (206) UNRELEASED; urgency=medium
6
7 * Fix flake8 violations.
8 * Refactor extra status handling to be common to all build types.
9+ * Fix handling of empty output in Backend.find.
10
11 -- Colin Watson <cjwatson@ubuntu.com> Wed, 08 Dec 2021 15:42:26 +0000
12
13diff --git a/lpbuildd/target/backend.py b/lpbuildd/target/backend.py
14index a7e778e..fb00dd4 100644
15--- a/lpbuildd/target/backend.py
16+++ b/lpbuildd/target/backend.py
17@@ -146,7 +146,7 @@ class Backend:
18 if name is not None:
19 cmd.extend(["-name", name])
20 cmd.extend(["-printf", "%P\\0"])
21- paths = self.run(cmd, get_output=True).rstrip(b"\0").split(b"\0")
22+ paths = self.run(cmd, get_output=True).split(b"\0")[:-1]
23 # XXX cjwatson 2017-08-04: Use `os.fsdecode` instead once we're on
24 # Python 3.
25 return [p.decode("UTF-8") for p in paths]
26diff --git a/lpbuildd/target/tests/test_chroot.py b/lpbuildd/target/tests/test_chroot.py
27index 8004fa9..10483e1 100644
28--- a/lpbuildd/target/tests/test_chroot.py
29+++ b/lpbuildd/target/tests/test_chroot.py
30@@ -255,6 +255,7 @@ class TestChroot(TestCase):
31 {"stdout": io.BytesIO(b"foo\0bar\0")},
32 {"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},
33 {"stdout": io.BytesIO(b"bar\0bar/bar\0")},
34+ {"stdout": io.BytesIO(b"")},
35 ])
36 processes_fixture.add(lambda _: next(test_proc_infos), name="sudo")
37 self.assertEqual(
38@@ -270,6 +271,9 @@ class TestChroot(TestCase):
39 self.assertEqual(
40 ["bar", "bar/bar"],
41 Chroot("1", "xenial", "amd64").find("/path", name="bar"))
42+ self.assertEqual(
43+ [],
44+ Chroot("1", "xenial", "amd64").find("/path", name="nonexistent"))
45
46 find_prefix = [
47 "sudo", "/usr/sbin/chroot",
48@@ -282,6 +286,7 @@ class TestChroot(TestCase):
49 find_prefix + ["-maxdepth", "1"] + find_suffix,
50 find_prefix + ["!", "-type", "d"] + find_suffix,
51 find_prefix + ["-name", "bar"] + find_suffix,
52+ find_prefix + ["-name", "nonexistent"] + find_suffix,
53 ]
54 self.assertEqual(
55 expected_args,
56diff --git a/lpbuildd/target/tests/test_lxd.py b/lpbuildd/target/tests/test_lxd.py
57index 35be3bb..15b2f1c 100644
58--- a/lpbuildd/target/tests/test_lxd.py
59+++ b/lpbuildd/target/tests/test_lxd.py
60@@ -797,6 +797,7 @@ class TestLXD(TestCase):
61 {"stdout": io.BytesIO(b"foo\0bar\0")},
62 {"stdout": io.BytesIO(b"foo\0bar/bar\0bar/baz\0")},
63 {"stdout": io.BytesIO(b"bar\0bar/bar\0")},
64+ {"stdout": io.BytesIO(b"")},
65 ])
66 processes_fixture.add(lambda _: next(test_proc_infos), name="lxc")
67 self.assertEqual(
68@@ -812,6 +813,8 @@ class TestLXD(TestCase):
69 self.assertEqual(
70 ["bar", "bar/bar"],
71 LXD("1", "xenial", "amd64").find("/path", name="bar"))
72+ self.assertEqual(
73+ [], LXD("1", "xenial", "amd64").find("/path", name="nonexistent"))
74
75 find_prefix = [
76 "lxc", "exec", "lp-xenial-amd64", "--",
77@@ -823,6 +826,7 @@ class TestLXD(TestCase):
78 find_prefix + ["-maxdepth", "1"] + find_suffix,
79 find_prefix + ["!", "-type", "d"] + find_suffix,
80 find_prefix + ["-name", "bar"] + find_suffix,
81+ find_prefix + ["-name", "nonexistent"] + find_suffix,
82 ]
83 self.assertEqual(
84 expected_args,

Subscribers

People subscribed via source and target branches