Skip to content
Open
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
45 changes: 24 additions & 21 deletions lib/batali/command/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ def execute!
units_slice.map do |unit|
Thread.new do
ui.debug "Starting unit install for: #{unit.name}<#{unit.version}>"
if unit.source.respond_to?(:cache_path)
unit.source.cache_path = cache_directory(
Bogo::Utility.snake(unit.source.class.name.split("::").last)
)
end
asset_path = unit.source.asset
final_path = Utility.join_path(install_path, unit.name)
if infrastructure?
final_path << "-#{unit.version}"
end
begin
FileUtils.cp_r(
Utility.join_path(asset_path, "."),
final_path
)
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)
ui.debug "Unit source: #{unit.source.inspect}"
unit.source.synchronize do
if unit.source.respond_to?(:cache_path)
unit.source.cache_path = cache_directory(
Bogo::Utility.snake(unit.source.class.name.split("::").last)
)
end
asset_path = unit.source.asset
final_path = Utility.join_path(install_path, unit.name)
if infrastructure?
final_path << "-#{unit.version}"
end
begin
FileUtils.cp_r(
Utility.join_path(asset_path, "."),
final_path
)
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)
end
end
end
end.map(&:join)
Expand Down
18 changes: 18 additions & 0 deletions lib/batali/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ def self.included(klass)
klass.class_eval do
attribute :url, String, :required => true, :equivalent => true
attribute :ref, String, :required => true, :equivalent => true

@@locks = {}
@@lock_init = Mutex.new

def self.path_lock(path)
@@lock_init.synchronize do
if !@@locks[path]
@@locks[path] = Mutex.new
end
end
if block_given?
@@locks[path].synchronize do
yield
end
else
@@locks[path]
end
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/batali/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def initialize(args = {})
super
end

# Helper to synchronize access to this source.
#
# @yield Block to be executed
# @return [Object]
def synchronize
yield
end

# @return [String]
def unit_version
raise NotImplementedError.new "Abstract class"
Expand Down
6 changes: 6 additions & 0 deletions lib/batali/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def initialize(*_, &block)
self.path = Utility.clean_path(path)
end

def synchronize
self.class.path_lock(path) do
yield
end
end

# @return [String] directory containing contents
def asset
clone_repository
Expand Down
7 changes: 4 additions & 3 deletions lib/batali/utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class Utility < Grimoire::Utility
# on platform in use
def self.clean_path(path)
if RUBY_PLATFORM =~ /mswin|mingw|windows/ &&
ENV["BATALI_DISABLE_UNC"].nil?
if !path.to_s.match(/^[A-Za-z]:/) && !path.start_with?(UNC_PATH)
ENV["BATALI_DISABLE_UNC"].nil? &&
path
if !path.to_s.match(/^[A-Za-z]:/) && !path.to_s.start_with?(UNC_PREFIX)
path = File.expand_path(path.to_s)
end
path = UNC_PREFIX + path unless path.start_with?(UNC_PATH)
path = UNC_PREFIX + path.to_s unless path.to_s.start_with?(UNC_PREFIX)
end
path
end
Expand Down