diff --git a/ext/go-plugin/vagrant/plugin/capabilities.go b/ext/go-plugin/vagrant/plugin/capabilities.go index 95129490b..bd5083270 100644 --- a/ext/go-plugin/vagrant/plugin/capabilities.go +++ b/ext/go-plugin/vagrant/plugin/capabilities.go @@ -64,45 +64,40 @@ func (s *GRPCGuestCapabilitiesServer) GuestCapabilities(ctx context.Context, req }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } return } func (s *GRPCGuestCapabilitiesServer) GuestCapability(ctx context.Context, req *vagrant_proto.GuestCapabilityRequest) (resp *vagrant_proto.GenericResponse, err error) { resp = &vagrant_proto.GenericResponse{} var args, r interface{} - if err = json.Unmarshal([]byte(req.Arguments), &args); err != nil { - return - } - machine, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } - cap := &vagrant.SystemCapability{ - Name: req.Capability.Name, - Platform: req.Capability.Platform} + var machine *vagrant.Machine n := make(chan struct{}) go func() { defer func() { n <- struct{}{} }() + if err = json.Unmarshal([]byte(req.Arguments), &args); err != nil { + return + } + machine, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + cap := &vagrant.SystemCapability{ + Name: req.Capability.Name, + Platform: req.Capability.Platform} r, err = s.Impl.GuestCapability(ctx, cap, args, machine) + var result []byte + result, err = json.Marshal(r) + if err != nil { + return + } + resp.Result = string(result) }() select { case <-ctx.Done(): case <-n: } - if err != nil { - return - } - result, err := json.Marshal(r) - if err != nil { - return - } - resp.Result = string(result) return } @@ -190,55 +185,52 @@ func (s *GRPCHostCapabilitiesServer) HostCapabilities(ctx context.Context, req * var r []vagrant.SystemCapability n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() r, err = s.Impl.HostCapabilities() - n <- struct{}{} + if err != nil { + return + } + for _, cap := range r { + rcap := &vagrant_proto.SystemCapability{Name: cap.Name, Platform: cap.Platform} + resp.Capabilities = append(resp.Capabilities, rcap) + } }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - for _, cap := range r { - rcap := &vagrant_proto.SystemCapability{Name: cap.Name, Platform: cap.Platform} - resp.Capabilities = append(resp.Capabilities, rcap) - } return } func (s *GRPCHostCapabilitiesServer) HostCapability(ctx context.Context, req *vagrant_proto.HostCapabilityRequest) (resp *vagrant_proto.GenericResponse, err error) { resp = &vagrant_proto.GenericResponse{} var args, r interface{} - if err = json.Unmarshal([]byte(req.Arguments), &args); err != nil { - return - } - env, err := vagrant.LoadEnvironment(req.Environment, s.Impl) - if err != nil { - return - } - cap := &vagrant.SystemCapability{ - Name: req.Capability.Name, - Platform: req.Capability.Platform} n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + if err = json.Unmarshal([]byte(req.Arguments), &args); err != nil { + return + } + env, err := vagrant.LoadEnvironment(req.Environment, s.Impl) + if err != nil { + return + } + cap := &vagrant.SystemCapability{ + Name: req.Capability.Name, + Platform: req.Capability.Platform} + r, err = s.Impl.HostCapability(ctx, cap, args, env) - n <- struct{}{} + var result []byte + result, err = json.Marshal(r) + if err != nil { + return + } + resp.Result = string(result) }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - result, err := json.Marshal(r) - if err != nil { - return - } - resp.Result = string(result) return } @@ -328,56 +320,54 @@ func (s *GRPCProviderCapabilitiesServer) ProviderCapabilities(ctx context.Contex var r []vagrant.ProviderCapability n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() r, err = s.Impl.ProviderCapabilities() - n <- struct{}{} + if err != nil { + return + } + for _, cap := range r { + rcap := &vagrant_proto.ProviderCapability{Name: cap.Name, Provider: cap.Provider} + resp.Capabilities = append(resp.Capabilities, rcap) + } }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - for _, cap := range r { - rcap := &vagrant_proto.ProviderCapability{Name: cap.Name, Provider: cap.Provider} - resp.Capabilities = append(resp.Capabilities, rcap) - } return } func (s *GRPCProviderCapabilitiesServer) ProviderCapability(ctx context.Context, req *vagrant_proto.ProviderCapabilityRequest) (resp *vagrant_proto.GenericResponse, err error) { resp = &vagrant_proto.GenericResponse{} + var m *vagrant.Machine var args, r interface{} - err = json.Unmarshal([]byte(req.Arguments), &args) - if err != nil { - return - } - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } - cap := &vagrant.ProviderCapability{ - Name: req.Capability.Name, - Provider: req.Capability.Provider} - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + err = json.Unmarshal([]byte(req.Arguments), &args) + if err != nil { + return + } + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + cap := &vagrant.ProviderCapability{ + Name: req.Capability.Name, + Provider: req.Capability.Provider} + r, err = s.Impl.ProviderCapability(ctx, cap, args, m) - n <- struct{}{} + var result []byte + result, err = json.Marshal(r) + if err != nil { + return + } + resp.Result = string(result) }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - result, err := json.Marshal(r) - if err != nil { - return - } - resp.Result = string(result) return } diff --git a/ext/go-plugin/vagrant/plugin/capabilities_test.go b/ext/go-plugin/vagrant/plugin/capabilities_test.go index 3993c705a..7fb78cac2 100644 --- a/ext/go-plugin/vagrant/plugin/capabilities_test.go +++ b/ext/go-plugin/vagrant/plugin/capabilities_test.go @@ -133,7 +133,7 @@ func TestCapabilities_GuestCapability_context_cancel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.GuestCapability(ctx, cap, args, m) n <- struct{}{} @@ -173,7 +173,7 @@ func TestCapabilities_GuestCapability_context_timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.GuestCapability(ctx, cap, args, m) n <- struct{}{} @@ -308,7 +308,7 @@ func TestCapabilities_HostCapability_context_cancel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.HostCapability(ctx, cap, args, e) n <- struct{}{} @@ -348,7 +348,7 @@ func TestCapabilities_HostCapability_context_timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.HostCapability(ctx, cap, args, e) n <- struct{}{} @@ -483,7 +483,7 @@ func TestCapabilities_ProviderCapability_context_cancel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.ProviderCapability(ctx, cap, args, m) n <- struct{}{} @@ -523,7 +523,7 @@ func TestCapabilities_ProviderCapability_context_timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.ProviderCapability(ctx, cap, args, m) n <- struct{}{} diff --git a/ext/go-plugin/vagrant/plugin/config.go b/ext/go-plugin/vagrant/plugin/config.go index 74d33c488..603253831 100644 --- a/ext/go-plugin/vagrant/plugin/config.go +++ b/ext/go-plugin/vagrant/plugin/config.go @@ -49,7 +49,7 @@ type GRPCConfigServer struct { func (s *GRPCConfigServer) ConfigAttributes(ctx context.Context, req *vagrant_proto.Empty) (resp *vagrant_proto.ListResponse, err error) { resp = &vagrant_proto.ListResponse{} - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { resp.Items, err = s.Impl.ConfigAttributes() n <- struct{}{} @@ -64,86 +64,77 @@ func (s *GRPCConfigServer) ConfigAttributes(ctx context.Context, req *vagrant_pr func (s *GRPCConfigServer) ConfigLoad(ctx context.Context, req *vagrant_proto.Configuration) (resp *vagrant_proto.Configuration, err error) { resp = &vagrant_proto.Configuration{} var data, r map[string]interface{} - err = json.Unmarshal([]byte(req.Data), &data) - if err != nil { - return - } n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + err = json.Unmarshal([]byte(req.Data), &data) + if err != nil { + return + } r, err = s.Impl.ConfigLoad(ctx, data) - n <- struct{}{} + var mdata []byte + mdata, err = json.Marshal(r) + if err != nil { + return + } + resp.Data = string(mdata) }() select { case <-ctx.Done(): - return case <-n: } - - if err != nil { - return - } - mdata, err := json.Marshal(r) - if err != nil { - return - } - - resp.Data = string(mdata) return } func (s *GRPCConfigServer) ConfigValidate(ctx context.Context, req *vagrant_proto.Configuration) (resp *vagrant_proto.ListResponse, err error) { resp = &vagrant_proto.ListResponse{} + var m *vagrant.Machine var data map[string]interface{} - err = json.Unmarshal([]byte(req.Data), &data) - if err != nil { - return - } - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + err = json.Unmarshal([]byte(req.Data), &data) + if err != nil { + return + } + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } resp.Items, err = s.Impl.ConfigValidate(ctx, data, m) - n <- struct{}{} }() select { case <-ctx.Done(): case <-n: } - return } func (s *GRPCConfigServer) ConfigFinalize(ctx context.Context, req *vagrant_proto.Configuration) (resp *vagrant_proto.Configuration, err error) { resp = &vagrant_proto.Configuration{} var data, r map[string]interface{} - err = json.Unmarshal([]byte(req.Data), &data) - if err != nil { - return - } n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + err = json.Unmarshal([]byte(req.Data), &data) + if err != nil { + return + } r, err = s.Impl.ConfigFinalize(ctx, data) - n <- struct{}{} + var mdata []byte + mdata, err = json.Marshal(r) + if err != nil { + return + } + resp.Data = string(mdata) }() select { case <-ctx.Done(): - return case <-n: } - - if err != nil { - return - } - mdata, err := json.Marshal(r) - if err != nil { - return - } - resp.Data = string(mdata) return } diff --git a/ext/go-plugin/vagrant/plugin/config_test.go b/ext/go-plugin/vagrant/plugin/config_test.go index 0e264a512..a84093524 100644 --- a/ext/go-plugin/vagrant/plugin/config_test.go +++ b/ext/go-plugin/vagrant/plugin/config_test.go @@ -84,7 +84,7 @@ func TestConfigPlugin_Load_context_timeout(t *testing.T) { data := map[string]interface{}{"pause": true} ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.ConfigLoad(ctx, data) n <- struct{}{} @@ -113,7 +113,7 @@ func TestConfigPlugin_Load_context_cancel(t *testing.T) { data := map[string]interface{}{"pause": true} ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.ConfigLoad(ctx, data) n <- struct{}{} @@ -180,7 +180,7 @@ func TestConfigPlugin_Validate_context_cancel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.ConfigValidate(ctx, data, machine) n <- struct{}{} @@ -254,7 +254,7 @@ func TestConfigPlugin_Finalize_context_cancel(t *testing.T) { "other_key": "other_val"} ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n := make(chan struct{}, 1) + n := make(chan struct{}) go func() { _, err = impl.ConfigFinalize(ctx, data) n <- struct{}{} diff --git a/ext/go-plugin/vagrant/plugin/io.go b/ext/go-plugin/vagrant/plugin/io.go index f90d51a29..dc3383456 100644 --- a/ext/go-plugin/vagrant/plugin/io.go +++ b/ext/go-plugin/vagrant/plugin/io.go @@ -44,14 +44,16 @@ func (s *GRPCIOServer) Write(ctx context.Context, req *vagrant_proto.Content) (r n := make(chan struct{}) bytes := 0 go func() { + defer func() { n <- struct{}{} }() bytes, err = s.Impl.Write(req.Value, req.Target) - n <- struct{}{} + if err != nil { + return + } + r.Length = int32(bytes) }() select { case <-ctx.Done(): - return case <-n: - r.Length = int32(bytes) } return } diff --git a/ext/go-plugin/vagrant/plugin/provider.go b/ext/go-plugin/vagrant/plugin/provider.go index 268bc6e84..77549cb5d 100644 --- a/ext/go-plugin/vagrant/plugin/provider.go +++ b/ext/go-plugin/vagrant/plugin/provider.go @@ -228,68 +228,71 @@ type GRPCProviderServer struct { } func (s *GRPCProviderServer) Action(ctx context.Context, req *vagrant_proto.GenericAction) (resp *vagrant_proto.ListResponse, err error) { + var ( + r []string + m *vagrant.Machine + ) resp = &vagrant_proto.ListResponse{} - var r []string n := make(chan struct{}) - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } go func() { + defer func() { n <- struct{}{} }() + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } r, err = s.Impl.Action(ctx, req.Name, m) + resp.Items = r n <- struct{}{} }() select { case <-ctx.Done(): - return case <-n: } - - if err != nil { - return - } - resp.Items = r return } func (s *GRPCProviderServer) RunAction(ctx context.Context, req *vagrant_proto.ExecuteAction) (resp *vagrant_proto.GenericResponse, err error) { + var ( + args, r interface{} + m *vagrant.Machine + ) resp = &vagrant_proto.GenericResponse{} - var args, r interface{} n := make(chan struct{}) - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } - err = json.Unmarshal([]byte(req.Data), &args) - if err != nil { - return - } go func() { + defer func() { n <- struct{}{} }() + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + err = json.Unmarshal([]byte(req.Data), &args) + if err != nil { + return + } r, err = s.Impl.RunAction(ctx, req.Name, args, m) - n <- struct{}{} + if err != nil { + return + } + result, err := json.Marshal(r) + if err != nil { + return + } + resp.Result = string(result) }() select { case <-ctx.Done(): - return case <-n: } - - if err != nil { - return - } - result, err := json.Marshal(r) - if err != nil { - return - } - resp.Result = string(result) return } func (s *GRPCProviderServer) Info(ctx context.Context, req *vagrant_proto.Empty) (*vagrant_proto.PluginInfo, error) { + resp := &vagrant_proto.PluginInfo{} var r *vagrant.ProviderInfo n := make(chan struct{}) go func() { r = s.Impl.Info() + resp.Description = r.Description + resp.Priority = r.Priority n <- struct{}{} }() select { @@ -297,86 +300,72 @@ func (s *GRPCProviderServer) Info(ctx context.Context, req *vagrant_proto.Empty) return nil, nil case <-n: } - - return &vagrant_proto.PluginInfo{ - Description: r.Description, - Priority: r.Priority}, nil + return resp, nil } func (s *GRPCProviderServer) IsInstalled(ctx context.Context, req *vagrant_proto.Machine) (resp *vagrant_proto.Valid, err error) { + var m *vagrant.Machine resp = &vagrant_proto.Valid{} - var r bool n := make(chan struct{}) - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } go func() { - r, err = s.Impl.IsInstalled(ctx, m) - n <- struct{}{} + defer func() { n <- struct{}{} }() + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + resp.Result, err = s.Impl.IsInstalled(ctx, m) }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - resp.Result = r return } func (s *GRPCProviderServer) IsUsable(ctx context.Context, req *vagrant_proto.Machine) (resp *vagrant_proto.Valid, err error) { + var m *vagrant.Machine resp = &vagrant_proto.Valid{} - var r bool n := make(chan struct{}) - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } go func() { - r, err = s.Impl.IsUsable(ctx, m) - n <- struct{}{} + defer func() { n <- struct{}{} }() + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + resp.Result, err = s.Impl.IsUsable(ctx, m) }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - resp.Result = r return } func (s *GRPCProviderServer) SshInfo(ctx context.Context, req *vagrant_proto.Machine) (resp *vagrant_proto.MachineSshInfo, err error) { resp = &vagrant_proto.MachineSshInfo{} var r *vagrant.SshInfo - n := make(chan struct{}, 1) - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } + var m *vagrant.Machine + n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } r, err = s.Impl.SshInfo(ctx, m) - n <- struct{}{} + if err != nil { + return + } + resp = &vagrant_proto.MachineSshInfo{ + Host: r.Host, + Port: r.Port, + Username: r.Username, + PrivateKeyPath: r.PrivateKeyPath} }() select { case <-ctx.Done(): - return case <-n: } - - if err != nil { - return - } - resp = &vagrant_proto.MachineSshInfo{ - Host: r.Host, - Port: r.Port, - Username: r.Username, - PrivateKeyPath: r.PrivateKeyPath} return } @@ -389,44 +378,48 @@ func (s *GRPCProviderServer) State(ctx context.Context, req *vagrant_proto.Machi return } go func() { + defer func() { n <- struct{}{} }() r, err = s.Impl.State(ctx, m) - n <- struct{}{} + if err != nil { + return + } + resp = &vagrant_proto.MachineState{ + Id: r.Id, + ShortDescription: r.ShortDesc, + LongDescription: r.LongDesc} }() select { case <-ctx.Done(): - return case <-n: } - - if err != nil { - return - } - resp = &vagrant_proto.MachineState{ - Id: r.Id, - ShortDescription: r.ShortDesc, - LongDescription: r.LongDesc} return } func (s *GRPCProviderServer) MachineIdChanged(ctx context.Context, req *vagrant_proto.Machine) (resp *vagrant_proto.Machine, err error) { + resp = &vagrant_proto.Machine{} + var mdata string + var m *vagrant.Machine n := make(chan struct{}) - m, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } go func() { + defer func() { n <- struct{}{} }() + m, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } err = s.Impl.MachineIdChanged(ctx, m) - n <- struct{}{} + if err != nil { + return + } + mdata, err = vagrant.DumpMachine(m) + if err != nil { + return + } + resp = &vagrant_proto.Machine{Machine: mdata} }() select { case <-ctx.Done(): case <-n: } - mdata, err := vagrant.DumpMachine(m) - if err != nil { - return - } - resp = &vagrant_proto.Machine{Machine: mdata} return } diff --git a/ext/go-plugin/vagrant/plugin/synced_folder.go b/ext/go-plugin/vagrant/plugin/synced_folder.go index 1eda362c5..73c4a9e42 100644 --- a/ext/go-plugin/vagrant/plugin/synced_folder.go +++ b/ext/go-plugin/vagrant/plugin/synced_folder.go @@ -153,19 +153,20 @@ type GRPCSyncedFolderServer struct { func (s *GRPCSyncedFolderServer) Cleanup(ctx context.Context, req *vagrant_proto.SyncedFolders) (resp *vagrant_proto.Empty, err error) { resp = &vagrant_proto.Empty{} - machine, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } - var options vagrant.FolderOptions - err = json.Unmarshal([]byte(req.Options), &options) - if err != nil { - return - } + var machine *vagrant.Machine n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + machine, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + var options vagrant.FolderOptions + err = json.Unmarshal([]byte(req.Options), &options) + if err != nil { + return + } err = s.Impl.Cleanup(ctx, machine, options) - n <- struct{}{} }() select { case <-ctx.Done(): @@ -176,24 +177,25 @@ func (s *GRPCSyncedFolderServer) Cleanup(ctx context.Context, req *vagrant_proto func (s *GRPCSyncedFolderServer) Disable(ctx context.Context, req *vagrant_proto.SyncedFolders) (resp *vagrant_proto.Empty, err error) { resp = &vagrant_proto.Empty{} - machine, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } - var folders vagrant.FolderList - err = json.Unmarshal([]byte(req.Folders), &folders) - if err != nil { - return - } - var options vagrant.FolderOptions - err = json.Unmarshal([]byte(req.Options), &options) - if err != nil { - return - } + var machine *vagrant.Machine n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + machine, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + var folders vagrant.FolderList + err = json.Unmarshal([]byte(req.Folders), &folders) + if err != nil { + return + } + var options vagrant.FolderOptions + err = json.Unmarshal([]byte(req.Options), &options) + if err != nil { + return + } err = s.Impl.Disable(ctx, machine, folders, options) - n <- struct{}{} }() select { case <-ctx.Done(): @@ -204,23 +206,40 @@ func (s *GRPCSyncedFolderServer) Disable(ctx context.Context, req *vagrant_proto func (s *GRPCSyncedFolderServer) Enable(ctx context.Context, req *vagrant_proto.SyncedFolders) (resp *vagrant_proto.Empty, err error) { resp = &vagrant_proto.Empty{} - machine, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } - var folders vagrant.FolderList - err = json.Unmarshal([]byte(req.Folders), &folders) - if err != nil { - return - } - var options vagrant.FolderOptions - err = json.Unmarshal([]byte(req.Options), &options) - if err != nil { - return - } + var machine *vagrant.Machine n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + machine, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } + var folders vagrant.FolderList + err = json.Unmarshal([]byte(req.Folders), &folders) + if err != nil { + return + } + var options vagrant.FolderOptions + err = json.Unmarshal([]byte(req.Options), &options) + if err != nil { + return + } err = s.Impl.Enable(ctx, machine, folders, options) + }() + select { + case <-ctx.Done(): + case <-n: + } + return +} + +func (s *GRPCSyncedFolderServer) Info(ctx context.Context, req *vagrant_proto.Empty) (resp *vagrant_proto.PluginInfo, err error) { + resp = &vagrant_proto.PluginInfo{} + n := make(chan struct{}) + go func() { + r := s.Impl.Info() + resp.Description = r.Description + resp.Priority = r.Priority n <- struct{}{} }() select { @@ -230,44 +249,24 @@ func (s *GRPCSyncedFolderServer) Enable(ctx context.Context, req *vagrant_proto. return } -func (s *GRPCSyncedFolderServer) Info(ctx context.Context, req *vagrant_proto.Empty) (*vagrant_proto.PluginInfo, error) { - n := make(chan struct{}) - var r *vagrant.SyncedFolderInfo - go func() { - r = s.Impl.Info() - n <- struct{}{} - }() - select { - case <-ctx.Done(): - return nil, nil - case <-n: - } - return &vagrant_proto.PluginInfo{ - Description: r.Description, - Priority: r.Priority}, nil -} - func (s *GRPCSyncedFolderServer) IsUsable(ctx context.Context, req *vagrant_proto.Machine) (resp *vagrant_proto.Valid, err error) { resp = &vagrant_proto.Valid{} + var machine *vagrant.Machine var r bool - machine, err := vagrant.LoadMachine(req.Machine, s.Impl) - if err != nil { - return - } n := make(chan struct{}) go func() { + defer func() { n <- struct{}{} }() + machine, err = vagrant.LoadMachine(req.Machine, s.Impl) + if err != nil { + return + } r, err = s.Impl.IsUsable(ctx, machine) - n <- struct{}{} + resp.Result = r }() select { case <-ctx.Done(): - return case <-n: } - if err != nil { - return - } - resp.Result = r return }