From 226dbccef81d9b00ff777e99683db9264e7fd017 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 4 Feb 2014 16:01:14 +0100 Subject: [PATCH] guests/linux: don't chown VB shared folders if readonly [GH-2442] --- CHANGELOG.md | 2 ++ .../linux/cap/mount_virtualbox_shared_folder.rb | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2790f7cfc..32ab4dee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,8 @@ BUG FIXES: rather than at runtime. - commands/ssh: When using `-c` on Windows, no more TTY errors. - guests/coreos: Restart etcd after configuring networks. [GH-2852] + - guests/linux: Don't chown VirtualBox synced folders if mounting + as readonly. [GH-2442] - guests/redhat: Set hostname to FQDN, per the documentation for RedHat. [GH-2792] - hosts/bsd: Don't invoke shell for NFS sudo calls. [GH-2808] diff --git a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb index 069614ded..c557097e6 100644 --- a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb @@ -62,13 +62,16 @@ module VagrantPlugins sleep 2 end - # Chown the directory to the proper user - chown_commands = [] - chown_commands << "chown #{mount_uid}:#{mount_gid} #{expanded_guest_path}" - chown_commands << "chown #{mount_uid}:#{mount_gid_old} #{expanded_guest_path}" + # Chown the directory to the proper user. We skip this if the + # mount options contained a readonly flag, because it won't work. + if !opts[:mount_options].include?("ro") + chown_commands = [] + chown_commands << "chown #{mount_uid}:#{mount_gid} #{expanded_guest_path}" + chown_commands << "chown #{mount_uid}:#{mount_gid_old} #{expanded_guest_path}" - exit_status = machine.communicate.sudo(chown_commands[0], error_check: false) - machine.communicate.sudo(chown_commands[1]) if exit_status != 0 + exit_status = machine.communicate.sudo(chown_commands[0], error_check: false) + machine.communicate.sudo(chown_commands[1]) if exit_status != 0 + end # Emit an upstart event if we can if machine.communicate.test("test -x /sbin/initctl")