Use path proto to pass around paths

This commit is contained in:
sophia 2021-12-13 16:24:34 -06:00 committed by Paul Hinze
parent 175f05657c
commit 38dd5ef5f9
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 22 additions and 12 deletions

View File

@ -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(

View File

@ -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

View File

@ -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,