Skip to content

Commit ac9f0ea

Browse files
committed
Avoid ingesting windows pathnames with backslashes -- convert to forward slashes
1 parent 22e514d commit ac9f0ea

6 files changed

+13
-23
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2424
- Referring to an undefined platform no longer causes a crash; it's now a helpful error message
2525
- A copy/paste error that prevented compiler warning flags from being supplied has been fixed, via jgfoster
2626
- RSpec was not communicating compile errors from unit test executables that failed to build. Now it does, via jgfoster
27+
- Windows paths now avoid picking up backslashes, for proper equality comparisons
2728

2829
### Security
2930

Diff for: lib/arduino_ci/arduino_downloader.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def self.autolocated_executable
4343
# The executable Arduino file in an existing installation, or nil
4444
# @return [Pathname]
4545
def self.existing_executable
46-
self.must_implement(__method__)
46+
Host.which("arduino-cli")
4747
end
4848

4949
# The local file (dir) name of the desired IDE package (zip/tar/etc)

Diff for: lib/arduino_ci/arduino_downloader_linux.rb

-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ def self.extracted_file
1717
"arduino-cli"
1818
end
1919

20-
# The executable Arduino file in an existing installation, or nil
21-
# @return [string]
22-
def self.existing_executable
23-
Host.which("arduino-cli")
24-
end
25-
2620
# Make any preparations or run any checks prior to making changes
2721
# @return [string] Error message, or nil if success
2822
def prepare

Diff for: lib/arduino_ci/arduino_downloader_osx.rb

-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ def self.extracted_file
1717
"arduino-cli"
1818
end
1919

20-
# The executable Arduino file in an existing installation, or nil
21-
# @return [string]
22-
def self.existing_executable
23-
Host.which("arduino-cli")
24-
end
25-
2620
# Make any preparations or run any checks prior to making changes
2721
# @return [string] Error message, or nil if success
2822
def prepare

Diff for: lib/arduino_ci/arduino_downloader_windows.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ def package_file
2828
"arduino-cli_#{@desired_version}_Windows_64bit.zip"
2929
end
3030

31-
# The executable Arduino file in an existing installation, or nil
32-
# @return [string]
33-
def self.existing_executable
34-
Host.which("arduino-cli")
35-
end
36-
3731
# The technology that will be used to extract the download
3832
# (for logging purposes)
3933
# @return [string]
@@ -57,5 +51,11 @@ def self.extracted_file
5751
"arduino-cli.exe"
5852
end
5953

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

Diff for: lib/arduino_ci/host.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ class Host
1717
# via https://stackoverflow.com/a/5471032/2063546
1818
# which('ruby') #=> /usr/bin/ruby
1919
# @param cmd [String] the command to search for
20-
# @return [String] the full path to the command if it exists
20+
# @return [Pathname] the full path to the command if it exists
2121
def self.which(cmd)
2222
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
23-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
23+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |string_path|
24+
path = OS.windows? ? windows_to_pathname(string_path) : Pathname.new(string_path)
2425
exts.each do |ext|
25-
exe = File.join(path, "#{cmd}#{ext}")
26-
return exe if File.executable?(exe) && !File.directory?(exe)
26+
exe = path.join("#{cmd}#{ext}")
27+
return exe if exe.executable? && !exe.directory?
2728
end
2829
end
2930
nil

0 commit comments

Comments
 (0)