diff --git a/plugins/communicators/winrm/command_filter.rb b/plugins/communicators/winrm/command_filter.rb index dcae3d1fc..4b5e2ab5c 100644 --- a/plugins/communicators/winrm/command_filter.rb +++ b/plugins/communicators/winrm/command_filter.rb @@ -8,6 +8,7 @@ module VagrantPlugins "cat", "chmod", "chown", + "grep", "rm", "test", "uname", diff --git a/plugins/communicators/winrm/command_filters/grep.rb b/plugins/communicators/winrm/command_filters/grep.rb new file mode 100644 index 000000000..96ce32ca6 --- /dev/null +++ b/plugins/communicators/winrm/command_filters/grep.rb @@ -0,0 +1,26 @@ +module VagrantPlugins + module CommunicatorWinRM + module CommandFilters + + # Converts a *nix 'grep' command to a PowerShell equivalent + class Grep + + def filter(command) + # grep 'Fedora release [12][67890]' /etc/redhat-release + # grep Funtoo /etc/gentoo-release + # grep Gentoo /etc/gentoo-release + + # grep is often used to detect the guest type in Vagrant, so don't bother running + # to speed up OS detection + '' + end + + def accept?(command) + command.start_with?('grep ') + end + + end + + end + end +end \ No newline at end of file diff --git a/test/unit/plugins/communicators/winrm/command_filter_test.rb b/test/unit/plugins/communicators/winrm/command_filter_test.rb index 71010154d..f226b8e9d 100644 --- a/test/unit/plugins/communicators/winrm/command_filter_test.rb +++ b/test/unit/plugins/communicators/winrm/command_filter_test.rb @@ -15,6 +15,10 @@ describe VagrantPlugins::CommunicatorWinRM::CommandFilter, :unit => true do expect(subject.filter('uname -s stuff')).to eq('') end + it 'filters out grep commands' do + expect(subject.filter("grep 'Fedora release [12][67890]' /etc/redhat-release")).to eq("") + end + it 'filters out which commands' do expect(subject.filter('which ruby')).to include( '[Array](Get-Command ruby -errorAction SilentlyContinue)')