If swap gets deleted entry from /etc/fstab gets also deleted

This commit is contained in:
Lucas Noki 2020-01-29 08:52:50 +01:00
parent b9bf1454ad
commit faac5d22be

View File

@ -126,6 +126,15 @@ class SwapModule(AbstractModule):
return
disable_swapfile = "sudo swapoff {} && ".format(swap_location) + \
"sudo rm {}".format(swap_location)
if self._check_fstab_entry() is True:
with open("/etc/fstab", "r") as fstab_out:
content = fstab_out.readlines()
with open("/etc/fstab", "w") as fstab_in:
content = content[:-1]
for line in content:
fstab_in.write(line)
else:
print("No entry in /etc/fstab!")
subprocess.call(disable_swapfile, shell=True)
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")