From 38dd5ef5f98bb313af88bb31eb3dc97b90e373ec Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 13 Dec 2021 16:24:34 -0600 Subject: [PATCH] Use path proto to pass around paths --- plugins/commands/serve/client/communicator.rb | 12 ++++-------- plugins/commands/serve/mappers/pathname.rb | 14 ++++++++++++++ .../commands/serve/service/communicator_service.rb | 8 ++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/commands/serve/client/communicator.rb b/plugins/commands/serve/client/communicator.rb index 8fc2e13a7..23f7f3c1f 100644 --- a/plugins/commands/serve/client/communicator.rb +++ b/plugins/commands/serve/client/communicator.rb @@ -70,10 +70,8 @@ module VagrantPlugins # @param [String] remote path # @param [String] local path def download(machine, from, to) - from_val = Google::Protobuf::Value.new - from_val.from_ruby(from) - to_val = Google::Protobuf::Value.new - to_val.from_ruby(to) + from_val = mapper.map(from, to: SDK::Args::Path) + to_val = mapper.map(to, to: SDK::Args::Path) req = SDK::FuncSpec::Args.new( args: [ SDK::FuncSpec::Value.new( @@ -100,10 +98,8 @@ module VagrantPlugins # @param [String] local path # @param [String] remote path def upload(machine, from, to) - from_val = Google::Protobuf::Value.new - from_val.from_ruby(from) - to_val = Google::Protobuf::Value.new - to_val.from_ruby(to) + from_val = mapper.map(from, to: SDK::Args::Path) + to_val = mapper.map(to, to: SDK::Args::Path) req = SDK::FuncSpec::Args.new( args: [ SDK::FuncSpec::Value.new( diff --git a/plugins/commands/serve/mappers/pathname.rb b/plugins/commands/serve/mappers/pathname.rb index 7b26b2c10..41a841412 100644 --- a/plugins/commands/serve/mappers/pathname.rb +++ b/plugins/commands/serve/mappers/pathname.rb @@ -47,6 +47,20 @@ module VagrantPlugins Pathname.new(path.path) end end + + class StringToPathname < Mapper + def initialize + super( + inputs: [Input.new(type: String)], + output: Pathname, + func: method(:converter), + ) + end + + def converter(path) + Pathname.new(path) + end + end end end end diff --git a/plugins/commands/serve/service/communicator_service.rb b/plugins/commands/serve/service/communicator_service.rb index 00a4b980b..22d798cfd 100644 --- a/plugins/commands/serve/service/communicator_service.rb +++ b/plugins/commands/serve/service/communicator_service.rb @@ -116,9 +116,9 @@ module VagrantPlugins with_info(ctx) do |info| plugin_name = info.plugin_name dest_proto = req.args.select{ |a| a.name == "destination" }.first - to = mapper.unany(dest_proto.value).to_ruby + to = mapper.map(dest_proto.value, to: Pathname).to_s source_proto = req.args.select{ |a| a.name == "source" }.first - from = mapper.unany(source_proto.value).to_ruby + from = mapper.map(source_proto.value, to: Pathname).to_s req.args.reject!{ |a| a.name == "source" || a.name == "destination" } machine = mapper.funcspec_map( req, mapper, broker, @@ -156,9 +156,9 @@ module VagrantPlugins with_info(ctx) do |info| plugin_name = info.plugin_name dest_proto = req.args.select{ |a| a.name == "destination" }.first - to = mapper.unany(dest_proto.value).to_ruby + to = mapper.map(dest_proto.value, to: Pathname).to_s source_proto = req.args.select{ |a| a.name == "source" }.first - from = mapper.unany(source_proto.value).to_ruby + from = mapper.map(source_proto.value, to: Pathname).to_s req.args.reject!{ |a| a.name == "source" || a.name == "destination" } machine = mapper.funcspec_map( req, mapper, broker,