[ruby-core:102125] [Ruby master Feature#17548] Need simple way to include symlink directories in Dir.glob
From:
keithrbennett@...
Date:
2021-01-17 15:42:43 UTC
List:
ruby-core #102125
Issue #17548 has been updated by keithrbennett (Keith Bennett).
By the way, this is what I was referring to when I mentioned "arcane workarounds":
https://stackoverflow.com/questions/357754/can-i-traverse-symlinked-directories-in-ruby-with-a-glob
(`Dir.glob("**{,/*/**}/*.rb")`)
----------------------------------------
Feature #17548: Need simple way to include symlink directories in Dir.glob
https://bugs.ruby-lang.org/issues/17548#change-89981
* Author: keithrbennett (Keith Bennett)
* Status: Open
* Priority: Normal
----------------------------------------
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.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>