Commit 5fea29e2 authored by Boris Bügling's avatar Boris Bügling

Merge pull request #4036 from CocoaPods/seg-locking

[Installer] Fix source locking/unlocking
parents 8e1ba8f2 befcc909
...@@ -115,7 +115,6 @@ module Pod ...@@ -115,7 +115,6 @@ module Pod
def prepare def prepare
UI.message 'Preparing' do UI.message 'Preparing' do
FileUtils.chmod_R('+w', sandbox.root)
sandbox.prepare sandbox.prepare
ensure_plugins_are_installed! ensure_plugins_are_installed!
Migrator.migrate(sandbox) Migrator.migrate(sandbox)
...@@ -307,18 +306,14 @@ module Pod ...@@ -307,18 +306,14 @@ module Pod
install_source_of_pod(spec.name) install_source_of_pod(spec.name)
end end
else else
UI.titled_section("Using #{spec}", title_options) UI.titled_section("Using #{spec}", title_options) do
create_pod_installer(spec.name)
end
end end
end end
end end
# Install the Pods. If the resolver indicated that a Pod should be def create_pod_installer(pod_name)
# installed and it exits, it is removed an then reinstalled. In any case if
# the Pod doesn't exits it is installed.
#
# @return [void]
#
def install_source_of_pod(pod_name)
specs_by_platform = {} specs_by_platform = {}
pod_targets.each do |pod_target| pod_targets.each do |pod_target|
if pod_target.root_spec.name == pod_name if pod_target.root_spec.name == pod_name
...@@ -329,9 +324,20 @@ module Pod ...@@ -329,9 +324,20 @@ module Pod
@pod_installers ||= [] @pod_installers ||= []
pod_installer = PodSourceInstaller.new(sandbox, specs_by_platform) pod_installer = PodSourceInstaller.new(sandbox, specs_by_platform)
pod_installer.install!
@pod_installers << pod_installer @pod_installers << pod_installer
@installed_specs.concat(specs_by_platform.values.flatten.uniq) pod_installer
end
# Install the Pods. If the resolver indicated that a Pod should be
# installed and it exits, it is removed an then reinstalled. In any case if
# the Pod doesn't exits it is installed.
#
# @return [void]
#
def install_source_of_pod(pod_name)
pod_installer = create_pod_installer(pod_name)
pod_installer.install!
@installed_specs.concat(pod_installer.specs_by_platform.values.flatten.uniq)
end end
# Cleans the sources of the Pods if the config instructs to do so. # Cleans the sources of the Pods if the config instructs to do so.
...@@ -344,6 +350,18 @@ module Pod ...@@ -344,6 +350,18 @@ module Pod
@pod_installers.each(&:clean!) @pod_installers.each(&:clean!)
end end
# Unlocks the sources of the Pods.
#
# @todo Why the @pod_installers might be empty?
#
def unlock_pod_sources
return unless @pod_installers
@pod_installers.each do |installer|
pod_target = pod_targets.find { |target| target.pod_name == installer.name }
installer.unlock_files!(pod_target.file_accessors)
end
end
# Locks the sources of the Pods if the config instructs to do so. # Locks the sources of the Pods if the config instructs to do so.
# #
# @todo Why the @pod_installers might be empty? # @todo Why the @pod_installers might be empty?
...@@ -444,6 +462,7 @@ module Pod ...@@ -444,6 +462,7 @@ module Pod
# @return [void] # @return [void]
# #
def perform_post_install_actions def perform_post_install_actions
unlock_pod_sources
run_plugins_post_install_hooks run_plugins_post_install_hooks
warn_for_deprecations warn_for_deprecations
lock_pod_sources lock_pod_sources
......
...@@ -74,12 +74,22 @@ module Pod ...@@ -74,12 +74,22 @@ module Pod
# #
def lock_files!(file_accessors) def lock_files!(file_accessors)
return if local? return if local?
each_source_file(file_accessors) do |source_file|
FileUtils.chmod('u-w', source_file)
end
end
file_accessors.each do |file_accessor| # Unlocks the source files if appropriate.
file_accessor.source_files.each do |source_file| #
next unless source_file.exist? # @todo As the pre install hooks need to run before cleaning this
FileUtils.chmod('-w', source_file) # method should be refactored.
end #
# @return [void]
#
def unlock_files!(file_accessors)
return if local?
each_source_file(file_accessors) do |source_file|
FileUtils.chmod('u+w', source_file)
end end
end end
...@@ -172,6 +182,15 @@ module Pod ...@@ -172,6 +182,15 @@ module Pod
!local? && !head_pod? && !predownloaded? && sandbox.specification(root_spec.name) != root_spec !local? && !head_pod? && !predownloaded? && sandbox.specification(root_spec.name) != root_spec
end end
def each_source_file(file_accessors, &blk)
file_accessors.each do |file_accessor|
file_accessor.source_files.each do |source_file|
next unless source_file.exist?
blk[source_file]
end
end
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment