Merge pull request #5793 from sjackman/install_symlink_p

install_symlink_p: Fix when dest includes a symlink
This commit is contained in:
Mike McQuaid 2019-03-17 12:39:41 +00:00 committed by GitHub
commit 587c8f0a10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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