class Lono::Md5
Public Class Methods
name(path)
click to toggle source
# File lib/lono/md5.rb, line 41 def name(path) relative_path = name_without_md5(path) relative_path = relative_path.sub(/\.(\w+)$/,'') # strip extension ext = File.directory?(path) ? "zip" : $1 md5 = sum(path) "#{relative_path}-#{md5}.#{ext}" end
name_without_md5(path)
click to toggle source
# File lib/lono/md5.rb, line 49 def name_without_md5(path) regexp = %r{.*/output/[\w_-]+/files/} path.sub(regexp, '') # relative_path w/o md5 end
sum(path)
click to toggle source
This checksum within the file name is to mainly make sure that Lambda::Function resources “change” and an update is triggered. There's another checksum in the upload code that makes sure we don't upload the code again to speed up things.
# File lib/lono/md5.rb, line 17 def sum(path) content = if File.directory?(path) sum_directory(path) else Digest::MD5.file(path).to_s[0..7] end md5 = Digest::MD5.new md5.update(content) md5.hexdigest.to_s[0..7] end
sum_directory(dir)
click to toggle source
# File lib/lono/md5.rb, line 30 def sum_directory(dir) files = Dir["#{dir}/**/*"] files = files.reject { |f| File.directory?(f) } .reject { |f| File.symlink?(f) } files.sort! files.map do |f| Digest::MD5.file(f).to_s[0..7] end.join end