Skip to content

redownload binary if it is corrupt #18

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

Merged
merged 1 commit into from
Jan 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/browserstack/localbinary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,35 @@ def download(dest_parent_dir)
binary_path
end

def verify_binary(binary_path)
binary_response = IO.popen(binary_path + " --version").readline
binary_response =~ /BrowserStack Local version \d+\.\d+/
rescue Exception => e
false
end

def binary_path
dest_parent_dir = get_available_dirs
binary_path = File.join(dest_parent_dir, "BrowserStackLocal#{".exe" if @windows}")

if File.exists? binary_path
binary_path
else
download(dest_parent_dir)
binary_path = download(dest_parent_dir)
end

valid_binary = verify_binary(binary_path)

if valid_binary
binary_path
else
binary_path = download(dest_parent_dir)
valid_binary = verify_binary(binary_path)
if valid_binary
binary_path
else
raise BrowserStack::LocalException.new('BrowserStack Local binary is corrupt')
end
end
end

Expand Down