Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set CI_MAX_FILENAME_LENGTH to avoid "File name too long" errors on Linux

  • Loading branch information...
commit 13278f034e7334e5dcda792b9524c9c9a6031d2b 1 parent fead38e
@samstokes samstokes authored
Showing with 23 additions and 1 deletion.
  1. +23 −1 lib/ci/reporter/report_manager.rb
View
24 lib/ci/reporter/report_manager.rb
@@ -7,17 +7,39 @@
module CI #:nodoc:
module Reporter #:nodoc:
class ReportManager
+ UNIQUE_SUFFIX_LENGTH = 8
+
def initialize(prefix)
@basedir = ENV['CI_REPORTS'] || File.expand_path("#{Dir.getwd}/#{prefix.downcase}/reports")
@basename = "#{@basedir}/#{prefix.upcase}"
+ @max_filename_length = ENV['CI_MAX_FILENAME_LENGTH'].to_i
+ if @max_filename_length != 0
+ min_acceptable_max = UNIQUE_SUFFIX_LENGTH + '.xml'.length
+ unless @max_filename_length > min_acceptable_max
+ raise ArgumentError, "CI_MAX_FILENAME_LENGTH must exceed #{min_acceptable_max}!"
+ end
+ @max_filename_length -= '.xml'.length
+ end
FileUtils.mkdir_p(@basedir)
end
def write_report(suite)
- File.open("#{@basename}-#{suite.name.gsub(/[^a-zA-Z0-9]+/, '-')}.xml", "w") do |f|
+ File.open(report_filename(suite), "w") do |f|
f << suite.to_xml
end
end
+
+ private
+ def report_filename(suite)
+ ideal = "#{@basename}-#{suite.name.gsub(/[^a-zA-Z0-9]+/, '-')}"
+
+ if @max_filename_length == 0 || ideal.length <= @max_filename_length
+ return "#{ideal}.xml"
+ end
+
+ suffix = "%0#{UNIQUE_SUFFIX_LENGTH}d" % rand(10 ** UNIQUE_SUFFIX_LENGTH)
+ ideal[0, @max_filename_length - UNIQUE_SUFFIX_LENGTH] + suffix + '.xml'
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.