Merge pull request #5103 from reitermarkus/incomplete-downloads

Fix cleanup of incomplete downloads.
This commit is contained in:
Markus Reiter 2018-10-15 15:19:56 +02:00 committed by GitHub
commit 473155e12c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -152,13 +152,13 @@ module Homebrew
def clean!
if args.empty?
cleanup_lockfiles
Formula.installed.sort_by(&:name).each do |formula|
cleanup_formula(formula)
end
cleanup_cache
cleanup_logs
cleanup_portable_ruby
cleanup_lockfiles
return if dry_run?
cleanup_old_cache_db
@ -221,14 +221,27 @@ module Homebrew
return if dry_run?
return unless (cache/"downloads").directory?
# We can't use `.reject(&:incomplete?) here due to the refinement scope.
downloads = (cache/"downloads").children.reject { |path| path.incomplete? } # rubocop:disable Style/SymbolProc
downloads = (cache/"downloads").children
referenced_downloads = [cache, cache/"Cask"].select(&:directory?)
.flat_map(&:children)
.select(&:symlink?)
.map(&:resolved_path)
(downloads - referenced_downloads).each(&:unlink)
(downloads - referenced_downloads).each do |download|
if download.incomplete?
begin
LockFile.new(download.basename).with_lock do
download.unlink
end
rescue OperationInProgressError
# Skip incomplete downloads which are still in progress.
next
end
else
download.unlink
end
end
end
def cleanup_cache(entries = nil)

View File

@ -277,6 +277,9 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
end
def fetch
download_lock = LockFile.new(temporary_path.basename)
download_lock.lock
urls = [url, *mirrors]
begin
@ -308,6 +311,8 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
puts "Trying a mirror..."
retry
end
ensure
download_lock.unlock
end
def clear_cache