Skip to content

Commit 4586e39

Browse files
committed
Fix crash of File.size(f) on Linux
Apparently File.size(non_existing_file) returns 0 on macOS but crashes on Linux (and thus CI)
1 parent 9e8f697 commit 4586e39

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class L10nHelper
1919
# - `nil` if the file does not exist or is neither of those format (e.g. not a `.strings` file at all)
2020
#
2121
def self.strings_file_type(path:)
22-
return :text if File.size(path).zero? # If completely empty file, consider it as a valid .strings files in textual format
22+
return :text if File.exist?(path) && File.size(path).zero? # If completely empty file, consider it as a valid `.strings` files in textual format
2323

2424
# Start by checking it seems like a valid property-list file (and not e.g. an image or plain text file)
2525
_, status = Open3.capture2('/usr/bin/plutil', '-lint', path)
@@ -57,7 +57,7 @@ def self.merge_strings(paths:, output_path:)
5757

5858
tmp_file.write("/* Generated File. Do not edit. */\n\n")
5959
paths.each do |input_file, prefix|
60-
next if File.size(input_file).zero? # Accept but skip totally-empty files
60+
next if File.exist?(input_file) && File.size(input_file).zero? # Accept but skip existing-but-totally-empty files (to avoid adding useless `MARK:` comment for them)
6161

6262
fmt = strings_file_type(path: input_file)
6363
raise "The file `#{input_file}` does not exist or is of unknown format." if fmt.nil?
@@ -94,7 +94,7 @@ def self.merge_strings(paths:, output_path:)
9494
# @raise [RuntimeError] If the file is not a valid strings file or there was an error in parsing its content.
9595
#
9696
def self.read_strings_file_as_hash(path:)
97-
return {} if File.size(path).zero? # Return empty hash if completely empty file
97+
return {} if File.exist?(path) && File.size(path).zero? # Return empty hash if completely empty file
9898

9999
output, status = Open3.capture2e('/usr/bin/plutil', '-convert', 'json', '-o', '-', path)
100100
raise output unless status.success?

0 commit comments

Comments
 (0)