Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! Add a preliminary checker to ensur…
Browse files Browse the repository at this point in the history
…e the mount points in /etc/fstab are in the correct order
  • Loading branch information
Mikhail Sandakov committed Nov 26, 2024
1 parent 7b629d3 commit a0d0fce
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pleskdistup/common/src/mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@ def get_fstab_configuration_misorderings(configpath: str) -> typing.List[typing.
if not os.path.exists(configpath):
return []

mount_points_order = {}
mount_points_order: typing.Dict[str, int] = {}
with open(configpath, "r") as f:
for iter, line in enumerate(f.readlines()):
if line.startswith("#") or line == "\n" or line == "":
continue
mount_point = line.split()[1]
mount_points_order[mount_point] = iter

misorderings = []
misorderings: typing.List[typing.Tuple[str, str]] = []
for mount_point in mount_points_order.keys():
if mount_point == "/":
continue

if "/" in mount_points_order and mount_points_order["/"] > mount_points_order[mount_point]:
misorderings.append(("/", mount_point))
parent_dir: str = mount_point
should_proceed: bool = True

parent_dir = os.path.dirname(mount_point)
while parent_dir != "/":
while should_proceed:
parent_dir = os.path.dirname(parent_dir)
if parent_dir in mount_points_order and mount_points_order[parent_dir] > mount_points_order[mount_point]:
misorderings.append((parent_dir, mount_point))
parent_dir = os.path.dirname(parent_dir)
if parent_dir == "/":
should_proceed = False

return misorderings

0 comments on commit a0d0fce

Please sign in to comment.