1

I have ~/work pointing to a directory on another partition using a symbolic link (ln -s...).

For example, ~ is on /dev/sda1, whereas ~/work is a link to a directory on /dev/sda2.

The array returned by Dir.glob('**', '*rb') does not include any files in ~/work.

Is there a way I can get glob to include ~/work files?

BernardK pointed out in his comment that this question was asked at Can I traverse symlinked directories in Ruby with a "**" glob?. The answer there is a bit arcane, and I am wondering if any modifications to the standard library regarding this issue have been made in the twelve years since that question was posted.

Keith Bennett
  • 4,722
  • 1
  • 25
  • 35
  • Have you seen ? – BernardK Jan 16 '21 at 22:55
  • Thanks. Yes, I found it after posting this, and was considering deleting this question. Would it be legitimate to rephrase it to ask if there have been any additions to the language regarding this issue since that post 12 years ago? I've modified the question to include this. – Keith Bennett Jan 16 '21 at 23:33
  • As a workaround I may just use `find -L` instead or Ruby's `Dir.glob`. This will follow the symbolic links, and also include files in hidden directories (e.g. `.rvm`!) by default. Unfortunately, this would not be portable to Windows though. – Keith Bennett Jan 16 '21 at 23:41
  • By the way, I've posted a feature request to the Ruby forum, at https://bugs.ruby-lang.org/issues/17548. – Keith Bennett Jan 17 '21 at 20:24

1 Answers1

1

I have read a lot of documentation, also about shell glob, the source code of Dir.glob, and haven't found any satisfactory answer (among others doc1 doc2 doc3 doc4 doc5).

I have created a symbolic link to a subdirectory on an external disk, containing 11 rb files. Then I cd to a certain directory containing sub-directories, ruby scripts and the symbolic link.

Dir.glob("**/*.rb") lists the 122 files that they contain, the symlink is not followed.

Dir.glob("**/*/**/b") gives 0 files.

Dir.glob("**{,/*/**}/*.rb") gives 255 files, twice the 122 + 11, the link is followed.

Finally I have found by chance : Dir.glob("**/*/**/*.rb") gives 133 files, the symbolic link is followed.

I have also tried

include File::Constants
d = Dir.glob("**/*/**/*.rb", File::NOFOLLOW)
print 'd size ', d.size; puts
puts d

but it makes no difference.

BernardK
  • 3,674
  • 2
  • 15
  • 10