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 f5a4bad
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 26 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
4 changes: 3 additions & 1 deletion lib/arduino_ci/arduino_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def config_dump

# @return [String] the path to the Arduino libraries directory
def lib_dir
Pathname.new(config_dump["directories"]["user"]) + "libraries"
user_dir_raw = config_dump["directories"]["user"]
user_dir = OS.windows? ? Host.windows_to_pathname(user_dir_raw) : user_dir_raw
Pathname.new(user_dir) + "libraries"
end

# Board manager URLs
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
1 change: 0 additions & 1 deletion spec/arduino_downloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
it "has correct class properties" do
ad = ArduinoCI::ArduinoDownloader

expect{ad.existing_executable}.to raise_error(NotImplementedError)
expect{ad.extracted_file}.to raise_error(NotImplementedError)
expect{ad.extracter}.to raise_error(NotImplementedError)
expect{ad.extract("foo")}.to raise_error(NotImplementedError)
Expand Down
2 changes: 1 addition & 1 deletion spec/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def with_tmpdir(path)
it "can find things with which" do
ruby_path = ArduinoCI::Host.which("ruby")
expect(ruby_path).not_to be nil
expect(ruby_path.include? "ruby").to be true
expect(ruby_path.to_s.include? "ruby").to be true
end
end

Expand Down

0 comments on commit f5a4bad

Please sign in to comment.