Fix cleanup of incomplete downloads.
This commit is contained in:
parent
9b84b2404a
commit
1f24c6600c
@ -152,13 +152,13 @@ module Homebrew
|
|||||||
|
|
||||||
def clean!
|
def clean!
|
||||||
if args.empty?
|
if args.empty?
|
||||||
cleanup_lockfiles
|
|
||||||
Formula.installed.sort_by(&:name).each do |formula|
|
Formula.installed.sort_by(&:name).each do |formula|
|
||||||
cleanup_formula(formula)
|
cleanup_formula(formula)
|
||||||
end
|
end
|
||||||
cleanup_cache
|
cleanup_cache
|
||||||
cleanup_logs
|
cleanup_logs
|
||||||
cleanup_portable_ruby
|
cleanup_portable_ruby
|
||||||
|
cleanup_lockfiles
|
||||||
return if dry_run?
|
return if dry_run?
|
||||||
|
|
||||||
cleanup_old_cache_db
|
cleanup_old_cache_db
|
||||||
@ -221,14 +221,27 @@ module Homebrew
|
|||||||
return if dry_run?
|
return if dry_run?
|
||||||
return unless (cache/"downloads").directory?
|
return unless (cache/"downloads").directory?
|
||||||
|
|
||||||
# We can't use `.reject(&:incomplete?) here due to the refinement scope.
|
downloads = (cache/"downloads").children
|
||||||
downloads = (cache/"downloads").children.reject { |path| path.incomplete? } # rubocop:disable Style/SymbolProc
|
|
||||||
referenced_downloads = [cache, cache/"Cask"].select(&:directory?)
|
referenced_downloads = [cache, cache/"Cask"].select(&:directory?)
|
||||||
.flat_map(&:children)
|
.flat_map(&:children)
|
||||||
.select(&:symlink?)
|
.select(&:symlink?)
|
||||||
.map(&:resolved_path)
|
.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
|
end
|
||||||
|
|
||||||
def cleanup_cache(entries = nil)
|
def cleanup_cache(entries = nil)
|
||||||
|
|||||||
@ -277,6 +277,9 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
|
download_lock = LockFile.new(temporary_path.basename)
|
||||||
|
download_lock.lock
|
||||||
|
|
||||||
urls = [url, *mirrors]
|
urls = [url, *mirrors]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -308,6 +311,8 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
puts "Trying a mirror..."
|
puts "Trying a mirror..."
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
download_lock.unlock
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_cache
|
def clear_cache
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user