diff --git a/internal/core/machine.go b/internal/core/machine.go index 911a72a54..a314e20f6 100644 --- a/internal/core/machine.go +++ b/internal/core/machine.go @@ -178,7 +178,21 @@ func (m *Machine) UID() (userId string, err error) { // SyncedFolders implements core.Machine func (m *Machine) SyncedFolders() (folders []core.SyncedFolder, err error) { - // TODO: need Vagrantfile + config := m.target.Configuration + machineConfig := config.ConfigVm + syncedFolders := machineConfig.SyncedFolders + + folders = []core.SyncedFolder{} + for _, folder := range syncedFolders { + // TODO: get default synced folder type + folder.Type = "virtualbox" + plg, err := m.project.basis.component(m.ctx, component.SyncedFolderType, folder.Type) + // TODO: configure with folder info + if err != nil { + return nil, err + } + folders = append(folders, plg.Value.(core.SyncedFolder)) + } return } diff --git a/lib/vagrant/machine/remote.rb b/lib/vagrant/machine/remote.rb index ab1bb1e12..bae8cdc86 100644 --- a/lib/vagrant/machine/remote.rb +++ b/lib/vagrant/machine/remote.rb @@ -371,8 +371,16 @@ module Vagrant end def synced_folders - # self.class.synced_folders(self) - client.synced_folders + folders = Vagrant::Plugin::V2::SyncedFolder::Collection.new + synced_folder_clients = client.synced_folders + @logger.debug("synced folder clients: #{synced_folder_clients}") + synced_folder_clients.each do |f| + # TODO: get type of synced folder and wrap it up in this hash + impl = "virtualbox" + sf = Vagrant::Plugin::V2::SyncedFolder.new._initialize(self, impl, f) + folders[impl] = {"id": {plugin: sf}} + end + folders end def to_proto diff --git a/lib/vagrant/plugin/v2/synced_folder/remote.rb b/lib/vagrant/plugin/v2/synced_folder/remote.rb index 869c7f408..c062bacf7 100644 --- a/lib/vagrant/plugin/v2/synced_folder/remote.rb +++ b/lib/vagrant/plugin/v2/synced_folder/remote.rb @@ -13,8 +13,14 @@ module Vagrant end end - def _initialize(machine, synced_folder_type) - @client = nil#TODO! + def _initialize(machine, synced_folder_type, client=nil) + @machine = machine + @client = client + if @client.nil? + raise ArgumentError, + "Remote client is required for `#{self.class.name}'" + end + @logger = Log4r::Logger.new("vagrant::synced_folder") self end @@ -62,7 +68,7 @@ module Vagrant # # @param [Symbol] cap_name Name of the capability def capability(cap_name, *args) - @logger.debug("running remote host capability #{cap_name} with args #{args}") + @logger.debug("running remote synced folder capability #{cap_name} with args #{args}") client.capability(cap_name, *args) end @@ -71,7 +77,7 @@ module Vagrant # @param [Symbol] cap_name Capability name # @return [Boolean] def capability?(cap_name) - @logger.debug("checking for remote host capability #{cap_name}") + @logger.debug("checking for remote synced folder capability #{cap_name}") client.has_capability?(cap_name) end diff --git a/plugins/commands/serve/client/target/machine.rb b/plugins/commands/serve/client/target/machine.rb index 3f9c758f6..658c51989 100644 --- a/plugins/commands/serve/client/target/machine.rb +++ b/plugins/commands/serve/client/target/machine.rb @@ -87,8 +87,11 @@ module VagrantPlugins client.set_state(req) end - # TODO: this is setup to return plugins. verify def synced_folders + folder_protos = client.synced_folders(Empty.new).synced_folders + folder_protos.map do |f| + SyncedFolder.load(f, broker: broker) + end end # @return [Integer] user ID that owns machine