From 12308301130e9e0220af653b127272eb694d2578 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Mon, 9 Dec 2024 13:56:37 +0200 Subject: [PATCH] Avoid infinite loop when mount point not started with "/" --- pleskdistup/common/src/mounts.py | 2 +- pleskdistup/common/tests/mountstests.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pleskdistup/common/src/mounts.py b/pleskdistup/common/src/mounts.py index 86b22f7..b4451b0 100644 --- a/pleskdistup/common/src/mounts.py +++ b/pleskdistup/common/src/mounts.py @@ -32,7 +32,7 @@ def get_fstab_configuration_misorderings(configpath: str) -> typing.List[typing. misorderings: typing.List[typing.Tuple[str, str]] = [] for mount_point in mount_points_order.keys(): - if mount_point == "/": + if mount_point == "/" or not mount_point.startswith("/"): continue parent_dir: str = mount_point diff --git a/pleskdistup/common/tests/mountstests.py b/pleskdistup/common/tests/mountstests.py index ea6aabc..a0d60ff 100644 --- a/pleskdistup/common/tests/mountstests.py +++ b/pleskdistup/common/tests/mountstests.py @@ -81,3 +81,12 @@ def test_file_without_root(self): f.write("devpts /dev/pts devpts gid=5,mode=620 0 0\n") f.write("tmpfs /dev/shm tmpfs defaults 0 0\n") self.assertEqual(mounts.get_fstab_configuration_misorderings(self.test_file_path), [("/home", "/home/test")]) + + def test_mount_point_is_swap(self): + with open(self.test_file_path, "w") as f: + f.write("# comment\n") + f.write("/dev/sda2 /var ext4 defaults 0 1\n") + f.write("/dev/sda5 swap swap defaults 0 1\n") + f.write("/dev/sda4 /home ext4 defaults 0 1\n") + + self.assertEqual(mounts.get_fstab_configuration_misorderings(self.test_file_path), [])