Merge pull request #10043 from chrisroberts/f-smb-localization

Remove localization dependency from SMB list generation
This commit is contained in:
Chris Roberts 2018-07-27 10:27:54 -07:00 committed by GitHub
commit 8ff29d5c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 19 deletions

View File

@ -133,16 +133,22 @@ module VagrantPlugins
if result.nil? if result.nil?
return nil return nil
end end
share_data = result.strip.lines
shares = {} shares = {}
name = nil name = nil
result.lines.each do |line| until share_data.empty?
key, value = line.split(":", 2).map(&:strip) content = share_data.take_while{|line| !line.strip.empty? }
if key == "Name" if content.size != 3
name = value @@logger.warn("expected SMB data check to be size 3 but was size #{content.size}")
shares[name] = {} @@logger.debug("unprocessed SMB data: #{content.inspect}")
next
end end
next if name.nil? || key.to_s.empty? share_name = content[0].strip.split(":", 2).last.strip
shares[name][key] = value shares[share_name] = {
"Path" => content[1].strip.split(":", 2).last.strip,
"Description" => content[2].strip.split(":", 2).last.strip
}
share_data.slice!(0, content.length + 1)
end end
shares shares
end end
@ -155,23 +161,24 @@ module VagrantPlugins
if result.nil? if result.nil?
return nil return nil
end end
result.sub!(/^.+?\-+/m, "") share_data = result.strip.lines
share_names = result.strip.split("\n").map do |line| # Remove header information
line.strip.split(/\s+/).first share_data.slice!(0, 2)
# Remove footer information
share_data.slice!(share_data.size - 1, share_data.size)
share_names = share_data.map do |line|
line.strip.split(/\s+/).first.strip
end end
# Last item is command completion notification so remove it
share_names.pop
shares = {} shares = {}
share_names.each do |share_name| share_names.each do |share_name|
shares[share_name] = {}
result = Vagrant::Util::PowerShell.execute_cmd("net share #{share_name} | Out-String -Width 4096") result = Vagrant::Util::PowerShell.execute_cmd("net share #{share_name} | Out-String -Width 4096")
next if result.nil? next if result.nil?
result.each_line do |line| result.strip!
key, value = line.strip.split(/\s+/, 2) share_info = result.lines
next if key == "Share name" shares[share_name] = {
key = "Description" if key == "Remark" "Path" => share_info[1].split(/\s+/, 2).last.strip,
shares[share_name][key] = value "Description" => share_info[2].split(/\s+/, 2).last.strip
end }
end end
shares shares
end end