fix an issue on windows when pushing theme/content assets

Aaron Barthel committed Jan 04, 2017
commit 254a58ee287a8a5d70b1b37f4243cc7b321fb036
Showing 2 changed files with 13 additions and 4 deletions
locomotive/wagon/decorators/content_asset_decorator.rb b/lib/locomotive/wagon/decorators/content_asset_decorator.rb +7 -2
@@ @@ -10,17 +10,22 @@ module Locomotive
end
def source
- Locomotive::Coal::UploadIO.new(filepath, nil, filename)
+ Locomotive::Coal::UploadIO.new(_readfile(filepath), nil, filename)
end
def checksum
- Digest::MD5.hexdigest(File.read(filepath))
+ Digest::MD5.hexdigest(_readfile(filepath) { |io| io.read })
end
def filename
File.basename(filepath)
end
+ private
+
+ def _readfile(path, &block)
+ File.open(path, 'rb', &block)
+ end
end
end
locomotive/wagon/decorators/theme_asset_decorator.rb b/lib/locomotive/wagon/decorators/theme_asset_decorator.rb +6 -2
@@ @@ -21,7 +21,7 @@ module Locomotive
end
def source
- Locomotive::Coal::UploadIO.new(filepath, nil, realname)
+ Locomotive::Coal::UploadIO.new(_readfile(filepath), nil, realname)
end
def priority
@@ @@ -33,7 +33,7 @@ module Locomotive
end
def checksum
- Digest::MD5.hexdigest(File.read(filepath))
+ Digest::MD5.hexdigest(_readfile(filepath) { |io| io.read })
end
# - memoize it because it will not change even if we change the filepath (or source)
@@ @@ -71,6 +71,10 @@ module Locomotive
File.basename(filename, extension) + new_extension
end
end
+
+ def _readfile(path, &block)
+ File.open(path, 'rb', &block)
+ end
end