Skip to content

Commit bcdcc3e

Browse files
committed
Remove SharedBitsPacker mixin
* This module was a holdover from the 'RegistryBitsPacker' for cf-4-k8s. Since it's only used by the LocalBitsPacker, we can just merge the two files again.
1 parent ef5df5c commit bcdcc3e

File tree

2 files changed

+79
-90
lines changed

2 files changed

+79
-90
lines changed

lib/cloud_controller/packager/local_bits_packer.rb

+79-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
require 'cloud_controller/blobstore/fingerprints_collection'
22
require 'cloud_controller/app_packager'
3-
require 'cloud_controller/packager/shared_bits_packer'
3+
require 'shellwords'
44

55
module CloudController
66
module Packager
77
class ConflictError < StandardError
88
end
99

1010
class LocalBitsPacker
11-
include Packager::SharedBitsPacker
12-
1311
def send_package_to_blobstore(blobstore_key, uploaded_package_zip, cached_files_fingerprints)
1412
tmp_dir = VCAP::CloudController::Config.config.get(:directories, :tmpdir)
1513
local_bits_packer_path = File.join(tmp_dir, "local_bits_packer-#{blobstore_key}")
@@ -39,6 +37,84 @@ def send_package_to_blobstore(blobstore_key, uploaded_package_zip, cached_files_
3937
def package_blobstore
4038
CloudController::DependencyLocator.instance.package_blobstore
4139
end
40+
41+
def package_zip_exists?(package_zip)
42+
package_zip && File.exist?(package_zip)
43+
end
44+
45+
def validate_size!(app_packager)
46+
return unless max_package_size
47+
48+
return unless app_packager.size > max_package_size
49+
50+
raise CloudController::Errors::ApiError.new_from_details('AppPackageInvalid', "Package may not be larger than #{max_package_size} bytes")
51+
end
52+
53+
def copy_uploaded_package(uploaded_package_zip, app_packager)
54+
FileUtils.chmod('u+w', uploaded_package_zip)
55+
FileUtils.cp(uploaded_package_zip, app_packager.path)
56+
end
57+
58+
def populate_resource_cache(app_packager, app_contents_path)
59+
FileUtils.mkdir(app_contents_path)
60+
app_packager.unzip(app_contents_path)
61+
62+
remove_symlinks(app_contents_path)
63+
64+
global_app_bits_cache.cp_r_to_blobstore(app_contents_path)
65+
end
66+
67+
def remove_symlinks(app_contents_path)
68+
Find.find(app_contents_path) do |path|
69+
File.delete(path) if File.symlink?(path)
70+
end
71+
end
72+
73+
def append_matched_resources(app_packager, cached_files_fingerprints, root_path)
74+
matched_resources = CloudController::Blobstore::FingerprintsCollection.new(cached_files_fingerprints, root_path)
75+
cached_resources_dir = File.join(root_path, 'cached_resources_dir')
76+
77+
FileUtils.mkdir(cached_resources_dir)
78+
checksum_mismatch = false
79+
matched_resources.each do |local_destination, file_sha, mode|
80+
file_path = File.join(cached_resources_dir, local_destination)
81+
global_app_bits_cache.download_from_blobstore(file_sha, File.join(cached_resources_dir, local_destination), mode:)
82+
83+
if Digester.new.digest_path(file_path) != file_sha
84+
checksum_mismatch = true
85+
global_app_bits_cache.delete(file_sha)
86+
end
87+
end
88+
89+
raise CloudController::Errors::ApiError.new_from_details('ResourceChecksumMismatch') if checksum_mismatch
90+
91+
app_packager.append_dir_contents(cached_resources_dir)
92+
end
93+
94+
def match_resources_and_validate_package(root_path, uploaded_package_zip, cached_files_fingerprints)
95+
app_packager = AppPackager.new(File.join(root_path, 'copied_app_package.zip'))
96+
app_contents_path = File.join(root_path, 'application_contents')
97+
98+
if package_zip_exists?(uploaded_package_zip)
99+
copy_uploaded_package(uploaded_package_zip, app_packager)
100+
validate_size!(app_packager)
101+
populate_resource_cache(app_packager, app_contents_path) unless VCAP::CloudController::FeatureFlag.disabled?(:resource_matching)
102+
end
103+
104+
append_matched_resources(app_packager, cached_files_fingerprints, root_path)
105+
106+
validate_size!(app_packager)
107+
app_packager.fix_subdir_permissions(root_path, app_contents_path)
108+
app_packager.path
109+
end
110+
111+
def max_package_size
112+
VCAP::CloudController::Config.config.get(:packages, :max_package_size)
113+
end
114+
115+
def global_app_bits_cache
116+
CloudController::DependencyLocator.instance.global_app_bits_cache
117+
end
42118
end
43119
end
44120
end

lib/cloud_controller/packager/shared_bits_packer.rb

-87
This file was deleted.

0 commit comments

Comments
 (0)