Project

General

Profile

Actions

Feature #17548

open

Need simple way to include symlink directories in Dir.glob

Added by keithrbennett (Keith Bennett) almost 4 years ago. Updated over 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:102118]

Description

I would like to suggest that Ruby provide a simple way to glob that includes the content of symlinked directories.

I have my Ruby projects in a ~/work directory that is symlinked to a directory an another partition.

For example, ~ is on /dev/sda1, whereas ~/work is a link to a directory on /dev/sda2. I need this because I want to operate on the same code bases regardless of which partition I boot from (they are various Linux distros).

The array returned by Dir.glob(Dir.home, '**', '*rb') does not include any files in ~/work. The size of that array is only 84. In contrast, when I use find ~ -name "*rb" | wc -l to get the number of files, I get 87,229 files.

I was hoping that one of the flags that can be passed to glob would help, but the only relevant one I found was to not follow links, which is the opposite of what I wanted.

There are arcane workarounds using fancy glob patterns, but I believe it's important that the language provide a simple way to accomplish this. (For example, the Unix find command has an -L option for this.) I understand that it may not be possible to retrofit it into the existing functions (glob and []), but even providing a different method (e.g. one named glob_include_links) would be ok. Or perhaps a glob2 method could be added that would include simple ways to specify that files in hidden directories should be included, in addition to the option to follow symlinks.

I admit that I have no idea how much effort this would be to implement, especially regarding Windows compatibility, but this would be nice to have.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0