Skip to content

Commit

Permalink
Avoid ingesting windows pathnames with backslashes -- convert to forw…
Browse files Browse the repository at this point in the history
…ard slashes
  • Loading branch information
ianfixes committed Apr 5, 2021
1 parent 22e514d commit ac9f0ea
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Referring to an undefined platform no longer causes a crash; it's now a helpful error message
- A copy/paste error that prevented compiler warning flags from being supplied has been fixed, via jgfoster
- RSpec was not communicating compile errors from unit test executables that failed to build. Now it does, via jgfoster
- Windows paths now avoid picking up backslashes, for proper equality comparisons

### Security

Expand Down
2 changes: 1 addition & 1 deletion lib/arduino_ci/arduino_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.autolocated_executable
# The executable Arduino file in an existing installation, or nil
# @return [Pathname]
def self.existing_executable
self.must_implement(__method__)
Host.which("arduino-cli")
end

# The local file (dir) name of the desired IDE package (zip/tar/etc)
Expand Down
6 changes: 0 additions & 6 deletions lib/arduino_ci/arduino_downloader_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ def self.extracted_file
"arduino-cli"
end

# The executable Arduino file in an existing installation, or nil
# @return [string]
def self.existing_executable
Host.which("arduino-cli")
end

# Make any preparations or run any checks prior to making changes
# @return [string] Error message, or nil if success
def prepare
Expand Down
6 changes: 0 additions & 6 deletions lib/arduino_ci/arduino_downloader_osx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ def self.extracted_file
"arduino-cli"
end

# The executable Arduino file in an existing installation, or nil
# @return [string]
def self.existing_executable
Host.which("arduino-cli")
end

# Make any preparations or run any checks prior to making changes
# @return [string] Error message, or nil if success
def prepare
Expand Down
12 changes: 6 additions & 6 deletions lib/arduino_ci/arduino_downloader_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ def package_file
"arduino-cli_#{@desired_version}_Windows_64bit.zip"
end

# The executable Arduino file in an existing installation, or nil
# @return [string]
def self.existing_executable
Host.which("arduino-cli")
end

# The technology that will be used to extract the download
# (for logging purposes)
# @return [string]
Expand All @@ -57,5 +51,11 @@ def self.extracted_file
"arduino-cli.exe"
end

# The executable Arduino file in a forced installation, or nil
# @return [Pathname]
def self.force_installed_executable
Pathname.new(Host.windows_to_pathname(ENV['HOME'])) + self.extracted_file
end

end
end
9 changes: 5 additions & 4 deletions lib/arduino_ci/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ class Host
# via https://stackoverflow.com/a/5471032/2063546
# which('ruby') #=> /usr/bin/ruby
# @param cmd [String] the command to search for
# @return [String] the full path to the command if it exists
# @return [Pathname] the full path to the command if it exists
def self.which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |string_path|
path = OS.windows? ? windows_to_pathname(string_path) : Pathname.new(string_path)
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
exe = path.join("#{cmd}#{ext}")
return exe if exe.executable? && !exe.directory?
end
end
nil
Expand Down

0 comments on commit ac9f0ea

Please sign in to comment.