Skip to content

Commit abe87b2

Browse files
emanuelsteentaru-garg-hashicorp
authored andcommitted
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.
1 parent 82fb402 commit abe87b2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

plugins/guests/linux/cap/persist_mount_shared_folder.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ def self.fstab_exists?(machine)
6464
machine.communicate.test("test -f /etc/fstab")
6565
end
6666

67+
def self.contains_vagrant_data?(machine)
68+
machine.communicate.test("grep '#VAGRANT-BEGIN' /etc/fstab")
69+
end
70+
6771
def self.remove_vagrant_managed_fstab(machine)
6872
if fstab_exists?(machine)
69-
machine.communicate.sudo("sed -i '/\#VAGRANT-BEGIN/,/\#VAGRANT-END/d' /etc/fstab")
73+
if contains_vagrant_data?(machine)
74+
machine.communicate.sudo("sed -i '/\#VAGRANT-BEGIN/,/\#VAGRANT-END/d' /etc/fstab")
75+
else
76+
@@logger.info("no vagrant data in fstab file, carrying on")
77+
end
7078
else
7179
@@logger.info("no fstab file found, carrying on")
7280
end

0 commit comments

Comments
 (0)