mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Move cached_location
to #initialize
.
This commit is contained in:
parent
528b4b367e
commit
51fa194966
@ -14,6 +14,7 @@ class AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_reader :cached_location
|
||||||
attr_reader :meta, :name, :version, :shutup
|
attr_reader :meta, :name, :version, :shutup
|
||||||
private :meta, :name, :version, :shutup
|
private :meta, :name, :version, :shutup
|
||||||
|
|
||||||
@ -68,10 +69,6 @@ class AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
private :chdir
|
private :chdir
|
||||||
|
|
||||||
# @!attribute [r] cached_location
|
|
||||||
# The path to the cached file or directory associated with the resource.
|
|
||||||
def cached_location; end
|
|
||||||
|
|
||||||
# @!attribute [r]
|
# @!attribute [r]
|
||||||
# return most recent modified time for all files in the current working directory after stage.
|
# return most recent modified time for all files in the current working directory after stage.
|
||||||
def source_modified_time
|
def source_modified_time
|
||||||
@ -108,7 +105,7 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
|
|||||||
super
|
super
|
||||||
@ref_type, @ref = extract_ref(meta)
|
@ref_type, @ref = extract_ref(meta)
|
||||||
@revision = meta[:revision]
|
@revision = meta[:revision]
|
||||||
@clone = HOMEBREW_CACHE/cache_filename
|
@cached_location = HOMEBREW_CACHE/"#{name}--#{cache_tag}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
@ -146,10 +143,6 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
|
|||||||
commit != @last_commit
|
commit != @last_commit
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_location
|
|
||||||
@clone
|
|
||||||
end
|
|
||||||
|
|
||||||
def head?
|
def head?
|
||||||
version.respond_to?(:head?) && version.head?
|
version.respond_to?(:head?) && version.head?
|
||||||
end
|
end
|
||||||
@ -166,10 +159,6 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_filename
|
|
||||||
"#{name}--#{cache_tag}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def repo_valid?
|
def repo_valid?
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
@ -187,6 +176,11 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
class AbstractFileDownloadStrategy < AbstractDownloadStrategy
|
class AbstractFileDownloadStrategy < AbstractDownloadStrategy
|
||||||
|
def initialize(url, name, version, **meta)
|
||||||
|
super
|
||||||
|
@cached_location = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
|
||||||
|
end
|
||||||
|
|
||||||
def stage
|
def stage
|
||||||
super
|
super
|
||||||
chdir
|
chdir
|
||||||
@ -209,12 +203,11 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
||||||
attr_reader :mirrors, :tarball_path, :temporary_path
|
attr_reader :mirrors, :temporary_path
|
||||||
|
|
||||||
def initialize(url, name, version, **meta)
|
def initialize(url, name, version, **meta)
|
||||||
super
|
super
|
||||||
@mirrors = meta.fetch(:mirrors, [])
|
@mirrors = meta.fetch(:mirrors, [])
|
||||||
@tarball_path = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
|
|
||||||
@temporary_path = Pathname.new("#{cached_location}.incomplete")
|
@temporary_path = Pathname.new("#{cached_location}.incomplete")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -238,10 +231,6 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_location
|
|
||||||
tarball_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_cache
|
def clear_cache
|
||||||
super
|
super
|
||||||
rm_rf(temporary_path)
|
rm_rf(temporary_path)
|
||||||
@ -366,8 +355,6 @@ end
|
|||||||
|
|
||||||
# This strategy extracts local binary packages.
|
# This strategy extracts local binary packages.
|
||||||
class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy
|
class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy
|
||||||
attr_reader :cached_location
|
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@cached_location = path
|
@cached_location = path
|
||||||
end
|
end
|
||||||
@ -520,11 +507,11 @@ end
|
|||||||
# url "scp://example.com/src/abc.1.0.tar.gz"
|
# url "scp://example.com/src/abc.1.0.tar.gz"
|
||||||
# ...
|
# ...
|
||||||
class ScpDownloadStrategy < AbstractFileDownloadStrategy
|
class ScpDownloadStrategy < AbstractFileDownloadStrategy
|
||||||
attr_reader :tarball_path, :temporary_path
|
attr_reader :temporary_path
|
||||||
|
|
||||||
def initialize(url, name, version, **meta)
|
def initialize(url, name, version, **meta)
|
||||||
super
|
super
|
||||||
@tarball_path = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
|
@cached_location = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
|
||||||
@temporary_path = Pathname.new("#{cached_location}.incomplete")
|
@temporary_path = Pathname.new("#{cached_location}.incomplete")
|
||||||
parse_url_pattern
|
parse_url_pattern
|
||||||
end
|
end
|
||||||
@ -554,10 +541,6 @@ class ScpDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_location
|
|
||||||
tarball_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_cache
|
def clear_cache
|
||||||
super
|
super
|
||||||
rm_rf(temporary_path)
|
rm_rf(temporary_path)
|
||||||
|
@ -234,8 +234,8 @@ describe CurlDownloadStrategy do
|
|||||||
expect(subject.send(:_curl_args)).to eq(["--user", "download:123456"])
|
expect(subject.send(:_curl_args)).to eq(["--user", "download:123456"])
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#tarball_path" do
|
describe "#cached_location" do
|
||||||
subject { described_class.new(url, name, version, **specs).tarball_path }
|
subject { described_class.new(url, name, version, **specs).cached_location }
|
||||||
|
|
||||||
context "when URL ends with file" do
|
context "when URL ends with file" do
|
||||||
it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") }
|
it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user