[elbe-devel] [PATCH 2/3] tests efilesystem: add a test for copy_fileslist and usrmerge

Torben Hohn torben.hohn at linutronix.de
Thu Mar 5 12:12:25 CET 2020


In buster /bin is just a link to /usr/bin. This poses problems with
elbepack.efilesystem.copy_filelist() for example when the link is absolute.

The current code will also not handle links to links properly.

Write 2 testcases for the usrmerge case.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/tests/test_efilesystem.py | 44 ++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 elbepack/tests/test_efilesystem.py

diff --git a/elbepack/tests/test_efilesystem.py b/elbepack/tests/test_efilesystem.py
new file mode 100644
index 000000000..d37eac291
--- /dev/null
+++ b/elbepack/tests/test_efilesystem.py
@@ -0,0 +1,44 @@
+
+import unittest
+
+from elbepack.filesystem import TmpdirFilesystem
+from elbepack.efilesystem import copy_filelist
+
+class TestCopyFilelist(unittest.TestCase):
+    def test_usrmerge_abs(self):
+        src = TmpdirFilesystem()
+        src.mkdir_p('/usr/bin')
+
+        # this will link to /usr/bin in the host RFS,
+        # when no special logic is applied.
+        src.symlink('/usr/bin', '/bin')
+
+        # we would actually want to write to /bin/bla
+        # but since the link points to /usr/bin without
+        # chroot, this is not possible.
+        src.write_file('/usr/bin/bla', 0o644, 'bla')
+
+        dst = TmpdirFilesystem()
+
+        copy_filelist(src, ['/bin', '/bin/bla'], dst)
+
+        self.assertEqual(dst.read_file('/usr/bin/bla'), 'bla')
+
+    def test_usrmerge_rel(self):
+        src = TmpdirFilesystem()
+        src.mkdir_p('/usr/bin')
+
+        # create a proper relative path, that should
+        # work fine from inside.
+        src.symlink('usr/bin', '/bin')
+
+        # we would actually want to write to /bin/bla
+        # but since the link points to /usr/bin without
+        # chroot, this is not possible.
+        src.write_file('/usr/bin/bla', 0o644, 'bla')
+
+        dst = TmpdirFilesystem()
+
+        copy_filelist(src, ['/bin', '/bin/bla'], dst)
+
+        self.assertEqual(dst.read_file('/usr/bin/bla'), 'bla')
-- 
2.20.1




More information about the elbe-devel mailing list