Skip to content

Commit 4dbe056

Browse files
authored
Merge pull request #21358 from ooye-sanket/patch-1
fix: cleanup removing shared resources needed by multiple formulas
2 parents 4bce0fe + 9ecc6a3 commit 4dbe056

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Library/Homebrew/download_queue.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def initialize(retries: 1, force: false, pour: false)
2929
@pool = T.let(Concurrent::FixedThreadPool.new(concurrency), Concurrent::FixedThreadPool)
3030
@tty = T.let($stdout.tty?, T::Boolean)
3131
@spinner = T.let(nil, T.nilable(Spinner))
32+
@symlink_targets = T.let({}, T::Hash[Pathname, T::Set[Downloadable]])
3233
end
3334

3435
sig {
@@ -38,6 +39,12 @@ def initialize(retries: 1, force: false, pour: false)
3839
).void
3940
}
4041
def enqueue(downloadable, check_attestation: false)
42+
cached_location = downloadable.cached_download
43+
44+
@symlink_targets[cached_location] ||= Set.new
45+
targets = @symlink_targets.fetch(cached_location)
46+
targets << downloadable
47+
4148
downloads[downloadable] ||= Concurrent::Promises.future_on(
4249
pool, RetryableDownload.new(downloadable, tries:, pour:),
4350
force, quiet, check_attestation
@@ -47,6 +54,7 @@ def enqueue(downloadable, check_attestation: false)
4754
if check_attestation && downloadable.is_a?(Bottle)
4855
Utils::Attestation.check_attestation(downloadable, quiet: true)
4956
end
57+
create_symlinks_for_shared_download(cached_location)
5058
end
5159
end
5260

@@ -186,6 +194,20 @@ def shutdown
186194

187195
private
188196

197+
sig { params(cached_location: Pathname).void }
198+
def create_symlinks_for_shared_download(cached_location)
199+
targets = @symlink_targets.fetch(cached_location, Set.new)
200+
targets.each do |target|
201+
downloader = target.downloader
202+
next unless downloader.is_a?(AbstractFileDownloadStrategy)
203+
204+
symlink_location = downloader.symlink_location
205+
next if symlink_location.symlink? && symlink_location.exist?
206+
207+
downloader.create_symlink_to_cached_download(cached_location)
208+
end
209+
end
210+
189211
sig { params(downloadable: Downloadable, exception: T.nilable(Exception)).returns(T::Boolean) }
190212
def bottle_manifest_error?(downloadable, exception)
191213
return false if exception.nil?

0 commit comments

Comments
 (0)