Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use glob strategy for file copy #92

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion batali.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'bogo-ui', '>= 0.1.6', '< 0.4'
s.add_runtime_dependency 'http', '>= 0.8.2', '< 1.0.0'
s.add_runtime_dependency 'git'
s.add_development_dependency 'rake'
s.add_development_dependency 'rake', '< 12'
s.add_development_dependency 'rubocop', '0.35.1'
s.add_development_dependency 'minitest'
s.add_development_dependency 'pry'
Expand Down
15 changes: 9 additions & 6 deletions lib/batali/command/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ def execute!
final_path << "-#{unit.version}"
end
begin
FileUtils.cp_r(
File.join(asset_path, '.'),
final_path
)
ui.debug "Copying assets from `#{asset_path}` to `#{final_path}`"
Dir.glob(File.join(asset_path, '**', '**', '*')).each do |asset_item|
if(File.file?(asset_item))
target_path = File.join(final_path, asset_item.sub(asset_path, ''))
FileUtils.mkdir_p(File.dirname(target_path))
FileUtils.copy(asset_item, target_path)
end
end
ui.debug "Completed unit install for: #{unit.name}<#{unit.version}>"
rescue => e
ui.debug "Failed unit install for: #{unit.name}<#{unit.version}> - #{e.class}: #{e}"
raise
ensure
unit.source.clean_asset(asset_path)
raise
end
end
end.map(&:join)
Expand Down
6 changes: 3 additions & 3 deletions lib/batali/source/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def asset
path = File.join(cache_directory, Base64.urlsafe_encode64(url))
if(File.directory?(path))
discovered_path = Dir.glob(File.join(path, '*')).reject do |i|
i.end_with?("#{File::SEPARATOR}asset")
i.end_with?('.batali-asset-file')
end.first
FileUtils.rm_rf(path)
end
Expand All @@ -65,7 +65,7 @@ def asset
while(result.code == 302)
result = HTTP.get(result.headers['Location'])
end
File.open(a_path = File.join(path, 'asset'), 'wb') do |file|
File.open(a_path = File.join(path, '.batali-asset-file'), 'wb') do |file|
while(content = result.body.readpartial(2048))
file.write content
end
Expand Down Expand Up @@ -99,7 +99,7 @@ def asset
raise
end
discovered_path = Dir.glob(File.join(path, '*')).reject do |i|
i.end_with?("#{File::SEPARATOR}asset")
i.end_with?('.batali-asset-file')
end.first
end
unless(discovered_path)
Expand Down