Merge pull request #5793 from sjackman/install_symlink_p
install_symlink_p: Fix when dest includes a symlink
This commit is contained in:
commit
587c8f0a10
@ -135,10 +135,11 @@ class Pathname
|
|||||||
end
|
end
|
||||||
|
|
||||||
def install_symlink_p(src, new_basename)
|
def install_symlink_p(src, new_basename)
|
||||||
src = Pathname(src).expand_path(self)
|
|
||||||
dst = join(new_basename)
|
|
||||||
mkpath
|
mkpath
|
||||||
FileUtils.ln_sf(src.relative_path_from(dst.parent), dst)
|
dstdir = realpath
|
||||||
|
src = Pathname(src).expand_path(dstdir)
|
||||||
|
src = src.dirname.realpath/src.basename if src.dirname.exist?
|
||||||
|
FileUtils.ln_sf(src.relative_path_from(dstdir), dstdir/new_basename)
|
||||||
end
|
end
|
||||||
private :install_symlink_p
|
private :install_symlink_p
|
||||||
|
|
||||||
|
|||||||
@ -245,6 +245,14 @@ describe Pathname do
|
|||||||
dst.install_symlink "foo" => "bar"
|
dst.install_symlink "foo" => "bar"
|
||||||
expect((dst/"bar").readlink).to eq(described_class.new("foo"))
|
expect((dst/"bar").readlink).to eq(described_class.new("foo"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can install relative symlinks in a symlinked directory" do
|
||||||
|
mkdir_p dst/"1/2"
|
||||||
|
dst.install_symlink "1/2" => "12"
|
||||||
|
expect((dst/"12").readlink).to eq(described_class.new("1/2"))
|
||||||
|
(dst/"12").install_symlink dst/"foo"
|
||||||
|
expect((dst/"12/foo").readlink).to eq(described_class.new("../../foo"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe InstallRenamed do
|
describe InstallRenamed do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user