# File lib/chef/client.rb, line 346
    def sync_cookbooks
      Chef::Log.debug("Synchronizing cookbooks")

      begin
        @events.cookbook_resolution_start(@expanded_run_list_with_versions)
        cookbook_hash = rest.post_rest("environments/#{@node.chef_environment}/cookbook_versions",
                                       {:run_list => @expanded_run_list_with_versions})
      rescue Exception => e
        # TODO: wrap/munge exception to provide helpful error output
        @events.cookbook_resolution_failed(@expanded_run_list_with_versions, e)
        raise
      else
        @events.cookbook_resolution_complete(cookbook_hash)
      end

      synchronizer = Chef::CookbookSynchronizer.new(cookbook_hash, @events)
      synchronizer.sync_cookbooks

      # register the file cache path in the cookbook path so that CookbookLoader actually picks up the synced cookbooks
      Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks")

      cookbook_hash
    end