Only clean up /etc/fstab if it really contains Vagrant data

This change, together with `allow_fstab_modification = false`, allows to run
a guest without root/sudo privileges which been broken since Vagrant 2.2.10.
This commit is contained in:
Emanuel Steen 2021-12-06 07:19:16 -06:00 committed by Taru Garg
parent 82fb402fef
commit abe87b2fdc

View file

@ -64,9 +64,17 @@ module VagrantPlugins
machine.communicate.test("test -f /etc/fstab")
end
def self.contains_vagrant_data?(machine)
machine.communicate.test("grep '#VAGRANT-BEGIN' /etc/fstab")
end
def self.remove_vagrant_managed_fstab(machine)
if fstab_exists?(machine)
machine.communicate.sudo("sed -i '/\#VAGRANT-BEGIN/,/\#VAGRANT-END/d' /etc/fstab")
if contains_vagrant_data?(machine)
machine.communicate.sudo("sed -i '/\#VAGRANT-BEGIN/,/\#VAGRANT-END/d' /etc/fstab")
else
@@logger.info("no vagrant data in fstab file, carrying on")
end
else
@@logger.info("no fstab file found, carrying on")
end