mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
resource: support relative paths as targets
of #stage
`#stage` takes an optional `target` argument, which specifies the location in which to unpack the `resource`. Passing relative paths to `#stage`, as in resource("foo").stage "bar" does not work, because this calls `Pathname("bar").install` inside the temporary directory that the contents of the resource are unpacked to. This means that passing a relative path to `#stage` has the unintended effect of moving files around inside a temporary directory the formula has no access to. Let's fix that by keeping track of the original working directory before `#stage` was called and prepending this to `target` whenever `target` is a relative path.
This commit is contained in:
parent
8dd96ae8ba
commit
a01715f0ee
@ -121,6 +121,7 @@ class Resource
|
|||||||
# is a {ResourceStageContext}.
|
# is a {ResourceStageContext}.
|
||||||
# A target or a block must be given, but not both.
|
# A target or a block must be given, but not both.
|
||||||
def unpack(target = nil)
|
def unpack(target = nil)
|
||||||
|
current_working_directory = Pathname.pwd
|
||||||
mktemp(download_name) do |staging|
|
mktemp(download_name) do |staging|
|
||||||
downloader.stage do
|
downloader.stage do
|
||||||
@source_modified_time = downloader.source_modified_time
|
@source_modified_time = downloader.source_modified_time
|
||||||
@ -129,6 +130,7 @@ class Resource
|
|||||||
yield ResourceStageContext.new(self, staging)
|
yield ResourceStageContext.new(self, staging)
|
||||||
elsif target
|
elsif target
|
||||||
target = Pathname(target)
|
target = Pathname(target)
|
||||||
|
target = current_working_directory/target if target.relative?
|
||||||
target.install Pathname.pwd.children
|
target.install Pathname.pwd.children
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user