Skip to content

Instantly share code, notes, and snippets.

@jpr5
Created September 9, 2010 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpr5/572489 to your computer and use it in GitHub Desktop.
Save jpr5/572489 to your computer and use it in GitHub Desktop.
# The last one is the important lesson -- if *any* component of the path has a
# symlink in it (not just the *last* component), Pathname#relative_path_from can
# still produce the wrong outcome.
#
# Admittedly, the example here would actually work because both the real dir and
# symlinked dir are both at the same level of path nesting. This example is just
# to demonstrate that Pathname#symlink? is an insufficient test in determining
# whether or not to call Pathname#realpath.
irb(main):001:0> require 'pathname'
=> true
irb(main):002:0> `mkdir -p dir_tmp/dir_build`
=> ""
irb(main):003:0> `ln -s dir_tmp sym_tmp`
=> ""
irb(main):004:0> Dir.chdir("dir_tmp") { `ln -s ../dir_tmp/dir_build sym_build` }
=> ""
irb(main):005:0> Pathname.new("sym_tmp").symlink?
=> true
irb(main):006:0> Pathname.new("sym_tmp/sym_build").symlink?
=> true
irb(main):007:0> Pathname.new("sym_tmp/dir_build").symlink?
=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment