# Found a Find.find() bug?

**URL:** <https://www.ruby-forum.com/t/found-a-find-find-bug/85722>\
**Category:** Ruby\
**Created:** [February 15, 2007, 8:54pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722 "2007-02-15T20:54:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 8:54pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/1 "2007-02-15T20:54:05Z")

</div>

I was trying out Find.find() today and found that if you pass it a  
directory without a trailing slash, it doesn’t traverse the directory.  
This seems like a bug to me. Is it? If so, how do I report it?

e.g.

require ‘find’  
Find.find("/tmp/") do |path|  
puts path  
end

vs.

require ‘find’  
Find.find("/tmp/") do |path|  
puts path  
end

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/2 "2007-02-15T22:22:15Z")

</div>

On 2/15/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> vs.
> 
> require ‘find’  
> Find.find(“/tmp/”) do |path|  
> puts path  
> end

Unless I’m missing something, your two examples are exactly  
the same.

I am running ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-freebsd6]

And I tried a quick test  
of: Find.find(“/tmp”)  
vs: Find.find(“/tmp/”)

And I seemed to get the same result from both. In my case, both  
tests found 131 directories and 27 “other things” (ie, “not  
directories”).

What platform are you running ruby on?  
Which version of ruby are you running?

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/3 "2007-02-15T22:42:17Z")

</div>

On Fri, 16 Feb 2007, Garance A Drosehn wrote:

> > Find.find("/tmp/") do |path|
> 
> tests found 131 directories and 27 “other things” (ie, “not directories”).
> 
> What platform are you running ruby on?  
> Which version of ruby are you running?

i **think** this could happen if /tmp were a soft link… ??

-a

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 10:53pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/4 "2007-02-15T22:53:18Z")

</div>

> > > Find.find("/tmp/") do |path|
> > 
> > tests found 131 directories and 27 “other things” (ie, “not directories”).
> > 
> > What platform are you running ruby on?  
> > Which version of ruby are you running?
> 
> i **think** this could happen if /tmp were a soft link… ??

It can using normal OS commands so I’d imagine the same is true with  
Ruby…

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/5 "2007-02-15T23:01:19Z")

</div>

On 2/15/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> directories").
> 
> > What platform are you running ruby on?  
> > Which version of ruby are you running?
> 
> i **think** this could happen if /tmp were a soft link… ??

Ooo. Good catch!

If I switch to testing this on MacOS 10, then ‘/tmp’ is a symlink  
to the directory ‘/private/tmp’. And in that case, I get:

found 1 dirs, 0 other types in ‘/tmp’.

vs

found 10 dirs, 27 other types in ‘/tmp/’.

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/6 "2007-02-15T23:15:21Z")

</div>

On Fri, Feb 16, 2007, removed\_email\_address@domain.invalid wrote:

> i **think** this could happen if /tmp were a soft link… ??

Yup! This bites me all the time on osx:

folio ~/projects \> ls /tmp  
/tmp@

folio ~/projects \> ls -l /tmp  
lrwxr-xr-x 1 root admin 11 Dec 12 15:34 /tmp@ -\> private/tmp

folio ~/projects \> ls /tmp/  
1f7ead7c295b42d3030a746438a8d222 2285/ …

Ben

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/7 "2007-02-15T23:09:21Z")

</div>

On 2/15/07, Garance A Drosehn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> found 1 dirs, 0 other types in '/tmp'.
> 
> ```
> 
> vs  
> found 10 dirs, 27 other types in ‘/tmp/’.

After spending another 10 seconds to think about this, I wonder if  
Find.find should throw an exception if passed in a symlink? As it  
is, Find.find() will only check the symlink itself if it was given a  
symlink.

I probably should take another 60 seconds to think about it, but I  
should move on to other email right now…

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [February 15, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/found-a-find-find-bug/85722/8 "2007-02-15T23:28:22Z")

</div>

On Fri, 16 Feb 2007, Ben B. wrote:

> folio ~/projects \> ls /tmp/  
> 1f7ead7c295b42d3030a746438a8d222 2285/ …
> 
> Ben

moral:

path = File.expand\_path path

😉

-a
