Skip to content

Commit 01b3d6c

Browse files
authored
Merge pull request #148 from fastlane/lk/read-in-binary-mode
Fix binary upload on Windows
2 parents 1e718dc + ff5fb28 commit 01b3d6c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/fastlane/plugin/firebase_app_distribution/client/firebase_app_distribution_api_client.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_upload_token(app_id, binary_path)
8989
if binary_path.nil? || !File.exist?(binary_path)
9090
UI.crash!("#{ErrorMessage.binary_not_found(@binary_type)}: #{binary_path}")
9191
end
92-
binary_hash = Digest::SHA256.hexdigest(File.open(binary_path).read)
92+
binary_hash = Digest::SHA256.hexdigest(read_binary(binary_path))
9393

9494
begin
9595
response = connection.get(v1_apps_url(app_id)) do |request|
@@ -114,7 +114,7 @@ def get_upload_token(app_id, binary_path)
114114
#
115115
# Throws a user_error if an invalid app id is passed in, or if the binary file does not exist
116116
def upload_binary(app_id, binary_path, platform)
117-
connection.post(binary_upload_url(app_id), File.open(binary_path).read) do |request|
117+
connection.post(binary_upload_url(app_id), read_binary(binary_path)) do |request|
118118
request.headers["Authorization"] = "Bearer " + @auth_token
119119
request.headers["X-APP-DISTRO-API-CLIENT-ID"] = "fastlane"
120120
request.headers["X-APP-DISTRO-API-CLIENT-TYPE"] = platform
@@ -223,6 +223,11 @@ def connection
223223
conn.adapter(Faraday.default_adapter)
224224
end
225225
end
226+
227+
def read_binary(path)
228+
# File must be read in binary mode to work on Windows
229+
File.open(path, 'rb').read
230+
end
226231
end
227232
end
228233
end

spec/firebase_app_distribution_api_client_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
before(:each) do
1818
allow(File).to receive(:open).and_call_original
1919
allow(File).to receive(:open)
20-
.with(fake_binary_path)
20+
.with(fake_binary_path, "rb")
2121
.and_return(fake_binary)
2222

2323
allow(File).to receive(:exist?).and_call_original
@@ -126,7 +126,7 @@
126126

127127
it 'crashes when given an invalid binary_path' do
128128
expect(File).to receive(:open)
129-
.with("invalid_binary_path")
129+
.with("invalid_binary_path", "rb")
130130
.and_raise(Errno::ENOENT.new("file not found"))
131131
expect { api_client.upload_binary("app_id", "invalid_binary_path", "android") }
132132
.to raise_error("#{ErrorMessage.binary_not_found('APK')}: invalid_binary_path")

0 commit comments

Comments
 (0)