New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Windows users with SSH installed to use 'vagrant ssh' #933
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
85ef23f
Enable Windows users with SSH installed to use 'vagrant ssh'
webcoyote 9acf9c5
Enable Windows users with SSH installed to use 'vagrant ssh'
webcoyote 3cff42c
Improved error message for SSHUnavailable on Windows
webcoyote f705070
Use Util::Platform.windows? to detect Windows properly; don't rely up…
webcoyote File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
module Vagrant | |||
module Util | |||
class FileUtil | |||
# Cross-platform way of finding an executable in the $PATH. | |||
# | |||
# which('ruby') #=> /usr/bin/ruby | |||
# by http://stackoverflow.com/users/11687/mislav | |||
# | |||
# This code is adapted from the following post by mislav: | |||
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby | |||
def self.which(cmd) | |||
|
|||
# If the PATHEXT variable is empty, we're on *nix and need to find the exact filename | |||
exts = nil | |||
if !Util::Platform.windows? || ENV['PATHEXT'].nil? | |||
exts = [''] | |||
# On Windows: if filename contains an extension, we must match that exact filename | |||
elsif File.extname(cmd).length != 0 | |||
exts = [''] | |||
# On Windows: otherwise try to match all possible executable file extensions (.EXE .COM .BAT etc.) | |||
else | |||
exts = ENV['PATHEXT'].split(';') | |||
end | |||
|
|||
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| | |||
exts.each do |ext| | |||
exe = "#{path}#{File::SEPARATOR}#{cmd}#{ext}" | |||
return exe if File.executable? exe | |||
end | |||
end | |||
|
|||
return nil | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
require File.expand_path("../../../base", __FILE__) | |||
|
|||
require 'vagrant/util/file_util' | |||
require 'vagrant/util/platform' | |||
|
|||
describe Vagrant::Util::FileUtil do | |||
|
|||
def tester (file_extension, test_extension, mode, &block) | |||
# create file in temp directory | |||
filename = '__vagrant_unit_test__' | |||
dir = Dir.tmpdir | |||
file = Pathname(dir) + (filename + file_extension) | |||
file.open("w") { |f| f.write("#") } | |||
file.chmod(mode) | |||
|
|||
# set the path to the directory where the file is located | |||
savepath = ENV['PATH'] | |||
ENV['PATH'] = dir.to_s | |||
block.call filename + test_extension | |||
ENV['PATH'] = savepath | |||
|
|||
file.unlink | |||
end | |||
|
|||
it "should return a path for an executable file" do | |||
tester '.bat', '.bat', 0755 do |name| | |||
Vagrant::Util::FileUtil.which(name).should_not be_nil | |||
end | |||
end | |||
|
|||
if Vagrant::Util::Platform.windows? | |||
it "should return a path for a Windows executable file" do | |||
tester '.bat', '', 0755 do |name| | |||
Vagrant::Util::FileUtil.which(name).should_not be_nil | |||
end | |||
end | |||
end | |||
|
|||
it "should return nil for a non-executable file" do | |||
tester '.txt', '.txt', 0644 do |name| | |||
Vagrant::Util::FileUtil.which(name).should be_nil | |||
end | |||
end | |||
|
|||
end | |||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@webcoyote
Would the following perhaps be safer?:
Config::CONFIG['host_os'].include? 'mswin'
It may prove to be safer to go with a system flag such as this over a mutable environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that using the PATHEXT variable as a way to detect Windows is
lame, but Config (deprecated) and RbConfig also seems to be fairly broken:
RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin/i ==> nil (bogus!)
RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin|mingw/i ==> 0 (found)
RUBY_PLATFORM ==> "i386-mingw32"
sigh.
However, it turns out that there is a "windows?" function in Util, part of
the vagrant project, so I'll use that.
Pat
On Mon, Jun 4, 2012 at 12:43 PM, Wil Moore III <
reply@reply.github.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@webcoyote Yeah, that's a bummer about RbConfig and RUBY_PLATFORM...but good call on the Util stuff :)