Create fstab if does not exist
This commit is contained in:
parent
93718a8f5b
commit
0831df2e7f
@ -17,11 +17,6 @@ module VagrantPlugins
|
||||
# @param [Machine] machine The machine to run the action on
|
||||
# @param [Map<String, Map>] A map of folders to add to fstab
|
||||
def self.persist_mount_shared_folder(machine, folders)
|
||||
if !fstab_exists?(machine)
|
||||
@@logger.info("no fstab file found, not modifying /etc/fstab")
|
||||
return
|
||||
end
|
||||
|
||||
if folders.nil?
|
||||
@@logger.info("clearing /etc/fstab")
|
||||
self.remove_vagrant_managed_fstab(machine)
|
||||
@ -66,7 +61,11 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
def self.remove_vagrant_managed_fstab(machine)
|
||||
if fstab_exists?(machine)
|
||||
machine.communicate.sudo("sed -i '/\#VAGRANT-BEGIN/,/\#VAGRANT-END/d' /etc/fstab")
|
||||
else
|
||||
@@logger.info("no fstab file found, carrying on")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -83,12 +83,20 @@ describe "VagrantPlugins::GuestLinux::Cap::PersistMountSharedFolder" do
|
||||
context "fstab does not exist" do
|
||||
before do
|
||||
allow(cap).to receive(:fstab_exists?).and_return(false)
|
||||
# Ensure /etc/fstab is not being modified
|
||||
expect(comm).not_to receive(:sudo).with(/sed -i .? \/etc\/fstab/)
|
||||
end
|
||||
|
||||
it "does not modify /etc/fstab" do
|
||||
expect(cap).not_to receive(:remove_vagrant_managed_fstab)
|
||||
it "creates /etc/fstab" do
|
||||
expect(cap).to receive(:remove_vagrant_managed_fstab)
|
||||
expect(comm).to receive(:sudo).with(/>> \/etc\/fstab/)
|
||||
cap.persist_mount_shared_folder(machine, [])
|
||||
end
|
||||
|
||||
it "does not remove contents of /etc/fstab" do
|
||||
expect(cap).to receive(:remove_vagrant_managed_fstab)
|
||||
expect(comm).not_to receive(:sudo).with(/echo '' >> \/etc\/fstab/)
|
||||
cap.persist_mount_shared_folder(machine, folders)
|
||||
cap.persist_mount_shared_folder(machine, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user